新手请教数据不能(update)

潜水的鱼 潜水的鱼 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

private void btnAlter_Click(object sender, System.EventArgs e)
{
OleDbConnection conn = new OleDbConnection(connStr);
OleDbCommand cmd = new OleDbCommand(@"update [user] set Name=@Name, Code=@Code, UserPassWord=@UserPassWord where id=@id", conn);

// MessageBox.Show(cmd.Parameters.Count.ToString());

cmd.Parameters.Add("@Name", txtUserName.Text.Trim().ToString());
cmd.Parameters.Add("@Code", txtUserCode.Text.Trim().ToString());
cmd.Parameters.Add("@id", int.Parse(txtId.Text.Trim().ToString()));
if (txtPassWord.Text.Trim().ToString() != txtReturnPassWord.Text.Trim().ToString())
{
MessageBox.Show("密码不一至");
return;
}
cmd.Parameters.Add("@UserPassWord", txtPassWord.Text.Trim().ToString());

try
{
conn.Open();
/* 测试, 有数据
foreach (OleDbParameter p in cmd.Parameters)
MessageBox.Show(p.Value.ToString());
*/
int i = cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("数据修改成功");
this.lvInfoDataBind();
}
catch(OleDbException x)
{
MessageBox.Show(x.Message);
}
catch(Exception x)
{
MessageBox.Show(x.Message);
}

}


大家帮帮忙,看看哪里有误, 运行完后, 会有“数据修改成功”提示,但没有任何错误提示, 可实际上数据没有修改成功
...全文
评论 18
收藏 已收藏
分享
返回顶部
潜水的鱼
C# 111,129 成员 642,538 内容