修改密码问题
修改密码如下:为什么有错呢,系统提示: cmd.ExecuteNonQuery(); 已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
protected void Page_Load(object sender, EventArgs e)
{
string user = Request["user"].ToString();//用户名
Label1 .Text= user ;
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
meteor.Open();
SqlCommand comm = new SqlCommand("select * from studentlogin where username='" + Label1.Text + "' and password='" + this.TextBox1.Text + "'", meteor);
SqlDataReader dr = comm.ExecuteReader();
if (!dr.Read())
{
Response.Write("<script>alert('原密码错误!')</script>");
dr.Close();
}
else
{
SqlCommand cmd = new SqlCommand("update studentlogin set password='" + TextBox2.Text + "'where username='" + Label1.Text + "'", meteor);
cmd.ExecuteNonQuery();
Response.Write("<script>alert(修改成功!'')</script>");
meteor.Close();
}
}