我初学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 = "";
            }

解决方案 »

  1.   

    先找本书看吧,如Visual C# 2005 管理系统开发经典案例
      

  2.   

      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 = ""; 
                }
      

  3.   

            //记录用户登录次数
            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();
                    }
                    else
                    {
                              this.MyTryCount += 1;
                    if (this.MyTryCount != 3)
                    {
                        int MyDoCount = 3 - this.MyTryCount;
                        MessageBox.Show("用户密码或用户名称有错,还有" + MyDoCount + "次机会!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.用户密码TextBox.Text = "";
                        this.用户名称TextBox.Text = "";                    
                    }
                    else
                    {
                        退出系统Button_Click(null, null);
                    }
                    }
                    if (MyConnection.State == ConnectionState.Open)
                    {
                        MyConnection.Close();
                    }
            }
      

  4.   

                if (comboBox2.Text == "")
                {
                    MessageBox.Show("用户名不能为空!");
                    return;
                }
                if (textBox3.Text == textBox4.Text)
                {
                    if (获取密码(comboBox2.Text) == textBox2.Text)
                    {
                        OleDbConnection con = new OleDbConnection(通用数据.连接字符串);
                        string ss = @"UPDATE user1 SET password1 = '" + textBox4.Text + "' WHERE (num = " + 用户编号 + ")";
                        OleDbCommand com = new OleDbCommand(ss, con);
                        con.Open();
                        com.ExecuteNonQuery();
                        con.Close();
                        MessageBox.Show("修改成功!");
                    }
                    else
                    {
                        MessageBox.Show("你输入的密码有误!请重试");
                    }
                }
                else
                {
                    MessageBox.Show("你两次输入的新密码不一致!请重试");
                }
      

  5.   

                if (comboBox2.Text == "")
                {
                    MessageBox.Show("用户名不能为空!");
                    return;
                }
                if (textBox3.Text == textBox4.Text)
                {
                    if (获取密码(comboBox2.Text) == textBox2.Text)
                    {
                        OleDbConnection con = new OleDbConnection(通用数据.连接字符串);
                        string ss = @"UPDATE user1 SET password1 = '" + textBox4.Text + "' WHERE (num = " + 用户编号 + ")";
                        OleDbCommand com = new OleDbCommand(ss, con);
                        con.Open();
                        com.ExecuteNonQuery();
                        con.Close();
                        MessageBox.Show("修改成功!");
                    }
                    else
                    {
                        MessageBox.Show("你输入的密码有误!请重试");
                    }
                }
                else
                {
                    MessageBox.Show("你两次输入的新密码不一致!请重试");
                }
      

  6.   

            private string 获取密码(string usename)
            {
                string 密码 = "";
                try
                {
                    OleDbConnection con = new OleDbConnection(通用数据.连接字符串);
                    string ss = @"SELECT TOP 1 password1, num FROM user1 WHERE (name1 = '" + usename + "')";
                    OleDbCommand com = new OleDbCommand(ss, con);
                    OleDbDataAdapter da = new OleDbDataAdapter(com);
                    DataSet ds = new DataSet();
                    con.Open();
                    ds.Clear();
                    da.Fill(ds);
                    con.Close();
                    密码 = ds.Tables[0].Rows[0][0].ToString();
                    用户编号 = ds.Tables[0].Rows[0][1].ToString();
                }
                catch { }
                return 密码;
            }