private void btnChange_Click(object sender, System.EventArgs e)
{
SqlConnection con=new SqlConnection(Application["conStr"].ToString());
con.Open();
string str="select * from users";
SqlCommand cmd=new SqlCommand(str,con);
SqlDataReader sdr=cmd.ExecuteReader();
string oldPassword=this.txtOldpassword.Text;
sdr.Read();
if(oldPassword==sdr["userPassword"].ToString().Trim())
{
sdr.Close();
string newPassword=this.txtOldpassword.Text;
string confirmNewpassword=this.txtConfirmNewpassword.Text;
if(newPassword==confirmNewpassword)
{
//这里你的con.Open();的连接并没有关闭,所以不必要在打开新的连接
//SqlConnection con1=new SqlConnection(Application["conStr"].ToString());
//con1.Open();
string str1="updata users set userPassword='"+newPassword+"' where userPassword='"+oldPassword+"'";
SqlCommand cmd1=new SqlCommand(str1,con);
//cmd1.ExecuteReader();
//这一句写错了,应该是实行sql语句,以后要注意
cmd1.ExecuteNonQuery();
cmd1.Dispose();
//con1.Close();
//con1.Dispose();
}
else
{
Response.Write("<script>alert('你两次输入的密码不一致,请重新输入!');</script>");
}
}
else
{
Response.Write("<script>alert('你的原始密码不正确,请重新输入!');</script>");
}
cmd.Dispose();
con.Close();
con.Dispose();
}
//总的来说这段代码有点乱,以后你要记得精简代码,asp.net 的代码一般不宜超过400行,做个修改密码不应写这么多