简单的SqlCECommand更新获胜';不起作用.为什么?
本文关键字:不起作用 为什么 SqlCECommand 更新 获胜 简单 | 更新日期: 2023-09-27 18:29:40
我不明白为什么这个简单的更新命令不起作用:
private void button1_Click(object sender, EventArgs e)
{
SqlCeCommand cmd = new SqlCeCommand("UPDATE tbl_Settings set password = '1234')", conn);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
错误消息:There was an error parsing the query. [ Token line number = 1,Token line offset = 42,Token in error = ) ]
我的选择和插入命令完美工作:
SqlCeCommand cmd = new SqlCeCommand("SELECT password FROM tbl_Settings", conn);
string password = cmd.ExecuteScalar().ToString();
您在查询中放置了一些错误的右大括号,请先将其删除。
把你的查询写在下面
SqlCeCommand cmd = new SqlCeCommand("UPDATE tbl_Settings set password = @pwd", conn);
cmd.Parameters.AddWithValue("@pwd","1234");
"UPDATE tbl_Settings set password = '1234')"
删除括号
"UPDATE tbl_Settings set password = '1234'"