我试图更新数据。每当我使用参数化查询时,它都会给出错误Fatal Error Encountered during command execution
。
这是我的代码:
public void updateAccount(Int32 cashierid, string cashieruser, string isadmin, string cashierfname, string cashiermname, string cashierlname, string cashierpass)
{
con.ConnectionString = conString;
String sql = "UPDATE cashieraccount SET cashieruser = ?cashieruser, cashierpass = ?cashierpass, isadmin = ?isadmin, cashierfname = ?cashierfname, cashiermname = ?cashiermname, cashierlname = ?cashierlname";
sql += "WHERE cashierid = ?cashierid";
try
{
con.Open();
MySqlCommand cmd = new MySqlCommand(sql, con);
cmd.Parameters.AddWithValue("?cashieruser", cashieruser);
cmd.Parameters.AddWithValue("?cashierpass", cashierpass);
cmd.Parameters.AddWithValue("?isadmin", isadmin);
cmd.Parameters.AddWithValue("?cashierfname", cashierfname);
cmd.Parameters.AddWithValue("?cashiermname", cashiermname);
cmd.Parameters.AddWithValue("?cashierlname", cashierlname);
cmd.Parameters.AddWithValue("?cashierid", cashierid);
cmd.ExecuteNonQuery(); **//Fatar Error Encountered during command execution**
}
finally
{
con.Close();
}
}
有人有任何建议吗?
答案 0 :(得分:4)
在where
子句之前,我在参数后面缺少一个空格:
String sql = "UPDATE cashieraccount SET cashieruser = ?cashieruser, cashierpass = ?cashierpass, isadmin = ?isadmin, cashierfname = ?cashierfname, cashiermname = ?cashiermname, cashierlname = ?cashierlname";
sql += " WHERE cashierid = ?cashierid";
// here ^