先输入原始用户名和密码,再输入新密码,点修改.

解决方案 »

  1.   

    update table set username='新' pwd='新' where username = '原' and password='原'
      

  2.   

    string conn=GetConnectionString();            string name = textBox1.Text.ToString().Trim();
                string oldpsw = textBox2.Text.ToString().Trim();
                string newpsw1 = textBox3.Text.ToString().Trim();
                string newpsw2 = textBox4.Text.ToString().Trim();            textBox1.Focus();            if (name == "")
                {
                    MessageBox.Show("请输入用户名!");
                    textBox1.Focus();
                }
                else if (oldpsw == "")
                {
                    MessageBox.Show("请输入密码!");
                    textBox2.Focus();
                }
                else if (newpsw1 == "")
                {
                    MessageBox.Show("请输入新密码!");
                    textBox3.Focus();
                }
                else if (newpsw2 == "")
                {
                    MessageBox.Show("请输入新密码");
                    textBox4.Focus();
                }
                else if (newpsw1 != newpsw2)
                {
                    MessageBox.Show("两次新密码不符");
                    textBox3.Focus();
                }
                else
                {                string queryString = "SELECT name,psw FROM admin";
                    bool flag = false;
                    using (OleDbConnection connection = new OleDbConnection(conn))
                    {
                        OleDbCommand command = new OleDbCommand(queryString, connection);
                        connection.Open();
                        OleDbDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            if (name == reader[0].ToString().Trim() && MD5Encrypt(oldpsw) == reader[1].ToString().Trim())
                            {
                                flag = true;
                                break;
                            }                    }
                        reader.Close();
                    }                if (flag == false)
                    {
                        MessageBox.Show("用户名或密码错误!");
                        this.textBox1.Focus();
                    }
                    else
                    {
                        string newpsw = MD5Encrypt(newpsw1);
                        string query = "UPDATE admin SET psw='" + newpsw + "' WHERE name='" + name + "'";
                        using (OleDbConnection connection = new OleDbConnection(conn))
                        {
                            connection.Open();
                            OleDbCommand command = new OleDbCommand(query, connection);
                            command.ExecuteNonQuery();
                        }
                        MessageBox.Show("修改成功!");
                        this.Close();
                    }
                }
      

  3.   

    页面框框都用RequireFieldValidator验证就行了,至于更新语句就参考楼上的,一楼的语句set 两项之间忘了逗号。