String password = this.textBox1.Text;
            String password1 = this.textBox2.Text;
            String password2 = this.textBox3.Text;
            if (!password1.Equals(password2))
            {
                MessageBox.Show ("两次密码输入不一致");
                return;
            }
            String cnno = "Data Source=HP-PC;Initial Catalog=FIRST;Integrated Security=True;Pooling=False";
            SqlConnection connection = new SqlConnection(cnno);
            string sql = string.Format("update Logind set Upw='{2}' where Uname='{0}'and Upw='{1}'", send_str, password, password1);
            connection.Open();
            SqlCommand command = new SqlCommand(sql, connection);
            int num = Convert.ToInt32(command.ExecuteScalar());            try
            {
                if (num > 0)
                {                    MessageBox.Show("修改成功!");
                }
                else
                {
                    MessageBox.Show("原密码错误!");
                }
            }
            catch (Exception ex)
            {                MessageBox.Show("错误异常" + ex);
            }
            finally
            {
                connection.Close();
            }这是我编写的修改密码的代码,可是不管我原密码输什么都可以修改怎么回事呢。。求指导

解决方案 »

  1.   

    具体怎么修改呢。。我以为where Uname='{0}'and Upw='{1}'"这句会自动比较是否一样
      

  2.   

    具体怎么修改呢。。我以为where Uname='{0}'and Upw='{1}'"这句会自动比较是否一样能说说嘛?
      

  3.   

    试试  int num = Convert.ToInt32(command.ExecuteScalar());
    =>
      int num =(int)command.ExecuteNonQuery();
      

  4.   


    确实 比较了
    ExecuteNonQuery();
    这个返回 的是 受影响的条数
    你说的
    “这是我编写的修改密码的代码,可是不管我原密码输什么都可以修改怎么回事呢。。求指导”
    是指 messagebox啊
    我以为
    你输入什么原密码都能修改 数据库呢。。
    你的messagebox显示的判定条件有问题