我想手动更改密码并将密码发送给我的用户,但我得到“对象引用未设置为对象的实例”。错误。我的鳕鱼有什么问题:谢谢:
Random r = new Random();
string code = r.Next(100000, 9999999).ToString();
//////////////////////////////////////////////////////////////////////////////////////////////
string connStr = ConfigurationManager.ConnectionStrings["****"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(connStr);
SqlCommand sqlcmd = new SqlCommand();
sqlcmd = new SqlCommand("SELECT Count(ID) FROM RolInfo where username=@username", sqlconn);
sqlcmd.Parameters.AddWithValue("@username", TextBox1.Text);
sqlconn.Open();
int count = ((int)sqlcmd.ExecuteScalar());
sqlconn.Close();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (count != 0)
{
Sendmail();
MembershipUser u = Membership.GetUser();
u.ChangePassword(u.ResetPassword(), code);
}
else
{
lab_Message.Visible = true;
lab_Message.Text = "This username is invalid.";
lab_Message.ForeColor = System.Drawing.Color.Red;
}
}
else
{
lab_Message.Visible = true;
lab_Message.Text = "Please enter your username.";
lab_Message.ForeColor = System.Drawing.Color.Red;
}
}