How to use MySQL user-variables with ADO.NET

痴心易碎 提交于 2019-12-29 09:05:53

问题


MySQL SQL commands can contain user variables that start with '@'.

The MySQL ADO.NET connector also uses '@' for command parameters.

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?


I'm trying to do something like this:

UPDATE company 
    SET next_job_id = @jobid:=next_job_id+1 
    WHERE company_id = @companyid; 
SELECT @jobid;

Where @jobid is a MySQL user variable and @companyid is a parameter.


回答1:


It's a connection string option - "Allow User Variables=true"

When set to true, parameters are prefixed with '?'.

Update: I've written up more on this, including how to get this to work with ADO.NET and Subsonic. See Here.



来源:https://stackoverflow.com/questions/4929792/how-to-use-mysql-user-variables-with-ado-net

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