PetaPoco parameter being treated as literal

假如想象 提交于 2019-12-12 01:59:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!