C#又求大神。。急。。新手
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();
}这是我编写的修改密码的代码,可是不管我原密码输什么都可以修改怎么回事呢。。求指导
[最优解释]
试试
int num = Convert.ToInt32(command.ExecuteScalar());
=>
int num =(int)command.ExecuteNonQuery();
[其他解释]
在修改之前先在数据库查一遍原密码正确不。
[其他解释]
貌似你根本没验证 原密码正确 否
就修改密码
只验证 2次密码输入是否一致
[其他解释]