PetaPoco参数被视为文字 [英] PetaPoco parameter being treated as literal
问题描述
我正在执行这样的PetaPoco更新语句:
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);
MySQL数据库只是将参数名称作为文字(即Html字段)粘贴到该字段中现在包含'@ 0'(不带引号)。
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).
我已经运行过这样的查询一千次了,但我在这一行中看不到错误。
我已经完成了PetaPoco代码,并创建了MySqlCommand,该MySqlCommand具有MySqlParameterCollection,该参数具有3个参数,并且它们都具有正确的值。
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.
知道我要去哪里了吗?
推荐答案
如果使用准备好的语句,则必须省略单个占位符周围的引号。使用
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);
相反。
这篇关于PetaPoco参数被视为文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!