private void Button1_Click(object sender, System.EventArgs e)
{  
string userpwd=Request.Equals("userPwd").ToString();
string strconn;
string strsel;
string strupdate;
            strconn="server=.;database=login;uid=sa;pwd=1984;";
strsel="select userPwd from login where userID='userId'";
strupdate="update login set userPwd='"+txtnewpwd+"' where userID='userId'";
SqlConnection conn=new SqlConnection(strconn);
SqlCommand  cmd=new SqlCommand(strsel,conn);
if(txtnewpwd.Text.Equals(""))
{
info.Text="新用户密码不能为空!";
}
else if(txtnewpwd.Text.Length<6)
{
info.Text="新用户密码不能小于6位!";
}

 if(txtoldpwd.Text!=userpwd.ToString())
 {

 info.Text="原密码错误";  txtoldpwd.Text="";
 txtnewpwd.Text="";
  
 }
                

else
{
SqlCommand comm=new SqlCommand(strupdate,conn);
comm.ExecuteNonQuery();

info.Text="修改成功";
txtoldpwd.Text="";
txtnewpwd.Text="";


}
}

}
请高手指点下呀  这是我做的密码修改 但是点修改时总是执行密码错误

解决方案 »

  1.   

    string userpwd=Request.Equals("userPwd").ToString();Request.Equals(object obj) 返回的是 Bool类型的数据 你拿一个旧密码比如 abc123 跟 true|false 去比较当然不对了
      

  2.   

    SqlDataReader sdr=cmd.ExecuteReader();
            if(sdr.Read())
            {
                if(txtoldpwd.Text!=sdr["passpord"].ToString())
                {
    sdr.close();
                    info.Text="原密码错误"; txtoldpwd.Text="";
     txtnewpwd.Text="";
                }
            }
      

  3.   

    string userID = this.txtID.text.trrm();
    string oldPass = this.txtPass.text.trim();
    string newPass = this.txtNewPass.text.trim();//新密码
    string newPassAffirm = this.txtNewPassAffirm.trim();//确认新密码//
    //前台用脚本验证  newPass == newPassAffirm 否?
    //string strCon = "server=sun;uid=sa;pwd=123;database=sunNews";SqlConnection conn = new SqlConnection(strCon);
    sqlCheck="select userPwd from sunNews where userID='" + userID + "' and userPwd = '"+ oldPass +"'";
    sqlUpdate="update sunNews set userPwd='"+ newPass +"' where userID='+ userID +'";SqlCommand comm = new SqlCommand(sqlCheck,conn);
    int ok = comm.ExecuteNonQuery();
    if(ok != 1)
    {
         Response.Write("<Script type='text/javascript'>");
         Response.Write("alert('无此用户')");
         Rsponse.Write("</Script>");
    }
    else
    {
       SqlCommand comm = new SqlCommand(sqlUpdate,conn); 
       if(1 == comm.ExecuteNonQuery())
       {
         Response.Write("<Script type='text/javascript'>");
         Response.Write("alert('修改成功')");
         Rsponse.Write("</Script>");
       }
       Response.Write("<Script type='text/javascript'>");
       Response.Write("alert('修改失败')");
       Rsponse.Write("</Script>");
     
    }
      

  4.   

    补充双引号:sqlUpdate="update sunNews set userPwd='"+ newPass +"' where userID='"+ userID +"'";