c#的一个修改密码的程序

写了一个c#修改密码的程序,但是跳出了成功更新密码的框但是数据库的资料未被改写求指点if(maskedTextBox3.Text==maskedTextBox2.Text... 写了一个c#修改密码的程序,但是跳出了成功更新密码的框但是数据库的资料未被改写求指点 if (maskedTextBox3.Text == maskedTextBox2.Text) { string userName = this.textBox1.Text.ToString(); string userPwd = this.maskedTextBox1.Text.ToString(); string newPwd = this.maskedTextBox2.Text.ToString(); SqlConnection conn = new SqlConnection("server=localhost;database=internet;uid=sa;pwd=lovlng0802;"); conn.Open(); SqlCommand cmd = new SqlCommand("select count(*) from login where username='" + userName + "'and password='" + userPwd + "'",conn); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count > 0) { SqlCommand update = new SqlCommand("update login set password='" + newPwd + "'where username = '" + userName + "'", conn); MessageBox.Show("密码更新完毕"); } else { MessageBox.Show("账户或密码错误"); } } else { MessageBox.Show("重复密码错误"); } } } }
conn.Open(); SqlCommand cmd = new SqlCommand("select count(*) from login where username='" + userName + "'and password='" + userPwd + "'",conn);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
SqlCommand update = new SqlCommand("update login set password='" + newPwd + "'where username = '" + userName + "'", conn);
MessageBox.Show("密码更新完毕");
}
展开
 我来答
xmandlp
2014-03-03 · TA获得超过484个赞
知道小有建树答主
回答量:498
采纳率:0%
帮助的人:312万
展开全部
if (count > 0)
{
SqlCommand update = new SqlCommand("update login set password='" + newPwd + "'where username = '" + userName + "'", conn);
MessageBox.Show("密码更新完毕");
}//这里的代码貌似有问题啊
数据库执行修改的操作咧?update.ExecuteNonQuery()没写?没写完整吧?
syht2000
高粉答主

2014-03-02 · 关注我不会让你失望
知道大有可为答主
回答量:3万
采纳率:79%
帮助的人:1.5亿
展开全部
最主要的错误,在更新 update那个sql上,where前面掉了一个空格,这个会导致你的update无效。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式