The Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Default=0 WHERE Default=1 AND UserID=3' at line 1
For some reason its not working i don't really see an error with this code.
Am trying to update database to set the default 0 if its 1 by the userid as you can see
Thank you very much.
try
{
using (
MySqlCommand cmd =
new MySqlCommand("UPDATE user_inventory SET Default=0 WHERE Default=1 AND UserID=@oid",
MysqlHandler.DbConnection))
{
cmd.Parameters.AddWithValue("@oid", user.UserId);
cmd.Prepare();
cmd.ExecuteNonQuery();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
I suspect the problem is that DEFAULT
is a reserved word. Ideally, change your schema to avoid using reserved words as field names. Alternatively, quote the name:
UPDATE user_inventory SET `Default`=0 WHERE `Default`=1 AND UserID=@oid
See more on this question at Stackoverflow