在Visual Studio 2008里用C#编写修改用户密码的代码大神们帮帮忙
2个回答
展开全部
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("密码更新成功!"); } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询