111,126
社区成员
发帖
与我相关
我的任务
分享private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim().Length == 0 || textBox2.Text.Trim().Length == 0 || textBox3.Text.Trim().Length == 0)
{
MessageBox.Show("请输入完整!");
return;
}
if (textBox2.Text.Trim() != textBox3.Text.Trim())
{
MessageBox.Show("两次密码输入不一致!");
return;
}
String ConnString = "Data Source=SQLSERVER名称或地址;Initial Catalog=CRMData;User ID=帐号;Password=密码";
SqlConnection conn = new SqlConnection(ConnString);
DataTable dt = new DataTable();
String sql = "SELECT * FROM Staff where 帐号= 系统帐号 and 密码 = " + textBox1.Text.Trim(); try
{
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(dt);
}
catch (Exception Err)
{
MessageBox.Show(Err.Message);
}
if (dt.Rows.Count == 0)
{
MessageBox.Show("旧密码输入错误!");
dt.Dispose();
}
else
{
sql = "UPDATE Staff set 密码 ='" + textBox2.Text.Trim() + "' where 帐号= '"+ 系统帐号 +"'";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sql;
cmd.Connection = conn;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception Err)
{
MessageBox.Show("更新出现异常!");
}
finally
{
conn.Close();
}
MessageBox.Show("密码更新成功!");
}
}