日期:2014-05-18  浏览次数:20901 次

新手求助,关于修改密码页面,请大家帮忙,谢谢
我初学c#,想做一个修改用户密码的窗体,连接的sql2000,我的思路是先连接数据库读取到该用户相应的密码,然后和textBoxOld对比,如果二者相等的话,继续验证新密码textBoxNew.Text和确认密码textBoxNewQueren.Text是否相等,若相等的话,就把新密码更新到原来的密码处。

不知道这个思路怎么样,写了一部分,然后就不太会写了,请大家帮帮我,谢谢大家。


  if (textBoxNewQueren.Text == textBoxNew.Text)
  {
   
  SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=db_showHouse;Integrated Security=True");
  SqlCommand cmd = new SqlCommand("select (*) from tb_User", conn);//不知道这么写对不对....
  conn.Open();
  string aa = cmd.EndExecuteNonQuery();
  conn.Close();
  if (aa == textBoxOld.Text)
  { 
  //更新数据库,不会写.......
  }


  }
  else
  {
  MessageBox.Show("您的密码输入有误,请重新输入!");
  textBoxNew.Text = "";
  textBoxNewQueren.Text = "";
  }

------解决方案--------------------
if (textBoxNewQueren.Text == textBoxNew.Text) 


SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=db_showHouse;Integrated Security=True"); 
SqlCommand cmd = new SqlCommand("select 密码 from tb_User where 用户名='"+用户名+"'", conn conn.Open(); 
string aa = (string)cmd.Excultscale(); 
if (aa == textBoxOld.Text) 

cme.CommaneText ="Update tb_User set 密码= '"+textBoxNew.Text+"' where 用户名='"+用户名+"'";
cmd.ExcultNoQuery();
conn.Close();

else
{
MessageBox.Show("密码不匹配!");
}



else 

MessageBox.Show("新密码和确认密码不一致,请重新输入!"); 
textBoxNew.Text = ""; 
textBoxNewQueren.Text = ""; 
}
------解决方案--------------------
//记录用户登录次数
private int MyTryCount = 0;
private void 登录系统Button_Click(object sender, EventArgs e)
{
//从app.config文件中读取数据库连接字符串信息
String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
string MySQL = "Select COUNT(*) From 操作用户 Where 用户名称=@用户名称 AND 用户密码=@用户密码";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand(MySQL, MyConnection);
MyCommand.Parameters.Clear();
SqlParameter MySqlNameParameter = new SqlParameter();
MySqlNameParameter.ParameterName = "@用户名称";
MySqlNameParameter.Value = this.用户名称TextBox.Text;
MyCommand.Parameters.Add(MySqlNameParameter);
SqlParameter MySqlPWParameter = new SqlParameter();
MySqlPWParameter.ParameterName = "@用户密码";
MySqlPWParameter.Value = this.用户密码TextBox.Text;
MyCommand.Parameters.Add(MySqlPWParameter);
int MyCount = (int)MyCommand.ExecuteScalar();
if (MyCount == 1)
{
this.Close();
}