以下是偶从这下的东东,不过在做的时候遇到了点问题,不能用。各位帮偶看看
login load=new login(); //login是登陆窗口的名称
string old=Pwd.Text.Trim(); //Pwd是原密码的TextBox
string newpassword1=NewPwd.Text.Trim(); //newPwd是新密码的TextBox
string newpassword2=sureNewPwd.Text.Trim(); //sureNewPwd是确认新密码的TextBox
string strconn="server=;uid=sa;pwd=;database=c#";
string strsql1="select * from admin";
string strsql2="update admin set 密码='"+newpassword1+"' where 姓名='"+load.Nowid+"'"; //load.Nowid不知道原作者是用来干什么的!
SqlConnection conn=new SqlConnection(strconn);
if(old!=""&&newpassword1!=""&&newpassword2!="")
{
if(newpassword1==newpassword2)
{
SqlDataAdapter da=new SqlDataAdapter(strsql1,conn);
DataSet ds=new DataSet();
da.Fill(ds,"admin");
DataTable dt=ds.Tables["admin"];
foreach(DataRow dr in dt.Rows)
{
if(dr["密码"].ToString()==load.Nowpassword&&dr["姓名"].ToString()==load.Nowid)
{
SqlCommand cmd=new SqlCommand(strsql2,conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("修改成功!");
abc=1;
}
}
if(abc==0)
MessageBox.Show("密码错误!");
}
else
MessageBox.Show("两次的密码不相同!");
}
else
MessageBox.Show("密码不能为空!");