问题
I'm executing a PetaPoco update statement like this:
db.Execute("UPDATE Content SET Html = '@0', PlainText = '@1' WHERE ContentId = @2", newHtml, newText, c.EmailContentId);
And the MySQL database is just sticking the parameter name into the field as a literal, i.e. the Html field now contains '@0' (without the quotes).
I've run queries like this a thousand times and I don't see the mistake in this line. I've stepped through the PetaPoco code and it creates the MySqlCommand, which has a MySqlParameterCollection, which has 3 parameters, and they all have the correct values.
Any idea where I'm going wrong?
回答1:
If you're using prepared statements, you've got to omit single quotes around your placeholders. Use
db.Execute("UPDATE Content SET Html = @0, PlainText = @1 WHERE ContentId = @2", newHtml, newText, c.EmailContentId);
instead.
来源:https://stackoverflow.com/questions/25251758/petapoco-parameter-being-treated-as-literal