如何使用MySQL的用户变量ADO.NET [英] How to use MySQL user-variables with ADO.NET
问题描述
MySQL的SQL命令可以包含以'@'用户变量。
MySQL SQL commands can contain user variables that start with '@'.
MySQL的ADO.NET连接器也使用@的命令参数。
The MySQL ADO.NET connector also uses '@' for command parameters.
有没有办法逃避的@字符,这样我就可以在通过ADO.NET发送到MySQL的SQL语句中使用用户变量?
Is there a way to escape the '@' character so I can use a user-variable in an SQL statement sent to MySQL via ADO.NET?
我试图做这样的事情:
UPDATE company
SET next_job_id = @jobid:=next_job_id+1
WHERE company_id = @companyid;
SELECT @jobid;
在哪里@jobid是一个MySQL用户变量和@companyid是一个参数。
Where @jobid is a MySQL user variable and @companyid is a parameter.
推荐答案
这是一个连接字符串选项 - 允许用户变量=真正的
It's a connection string option - "Allow User Variables=true"
当设置为true,参数pfixed与'?'$ P $。
When set to true, parameters are prefixed with '?'.
更新:我已经写了更多关于这个,包括如何得到这个使用ADO.NET和亚音速工作。 看到这里。
Update: I've written up more on this, including how to get this to work with ADO.NET and Subsonic. See Here.
这篇关于如何使用MySQL的用户变量ADO.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!