读书人

C#又求大神。生手

发布时间: 2012-12-16 12:02:32 作者: rapoo

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次密码输入是否一致
[其他解释]

引用:
在修改之前先在数据库查一遍原密码正确不。
具体怎么修改呢。。我以为where Uname='{0}'and Upw='{1}'"这句会自动比较是否一样。。。
[其他解释]
引用:
貌似你根本没验证 原密码正确 否
就修改密码
只验证 2次密码输入是否一致
具体怎么修改呢。。我以为where Uname='{0}'and Upw='{1}'"这句会自动比较是否一样。。。能说说嘛?
[其他解释]
引用:
试试

int num = Convert.ToInt32(command.ExecuteScalar());
=>
int num =(int)command.ExecuteNonQuery();
好了。。非常感谢。。
[其他解释]
引用:
引用:貌似你根本没验证 原密码正确 否
就修改密码
只验证 2次密码输入是否一致具体怎么修改呢。。我以为where Uname='{0}'and Upw='{1}'"这句会自动比较是否一样。。。能说说嘛?


确实 比较了。。。
ExecuteNonQuery();
这个返回 的是 受影响的条数


你说的
“这是我编写的修改密码的代码,可是不管我原密码输什么都可以修改怎么回事呢。。求指导”
是指 messagebox啊
我以为
你输入什么原密码都能修改 数据库呢。。
你的messagebox显示的判定条件有问题



读书人网 >C#

热点推荐