这是一个简单的SQL,为了这个问题。 (实际的SQL是比这更复杂)
SET @HELLO = 1;
选择@HELLO;
正如你所看到的。 @HELLO
是一个MySQL变量,但.NET的MySqlCommand对待,就好像它是一个占位符不是需要绑定值。反正我有可以使用MySQL变量,.NET?
看一看下面的 MySql.Data.MySqlClient.MySqlException:参数'@id'必须
其中规定
最后,我发现这确实是在净连接器的变化。 (我不知道是什么版本号,但开始从5.2.0将是我的 猜)从连接器,你应该添加的5.2.2版本开始 允许用户变量=真正的连接字符串设定为 使用用户定义的变量在您的SQL语句。
连接字符串的例子:
数据库= TESTDB;数据源=本地主机;用户ID =根;密码=你好;允许用户变量=真
This is a sample SQL for the sake of this question. (The actual SQL is more complicated than this one)
SET @HELLO = 1;
SELECT @HELLO;
As you can see. @HELLO
is a MySQL variable, but .NET MySQLCommand treats as if it is a placeholder than need to bind value. Is there anyway I can use MySQL variable with .NET?
Have a look at the following MySql.Data.MySqlClient.MySqlException: Parameter ‘@id’ must be defined
Which states
Finally, I found that this was indeed a change in the .Net Connector. (I’m not sure what version number but starting from 5.2.0 would be my guess) Starting from version 5.2.2 of the Connector you should add the Allow User Variables=True Connection String Setting in order to use User Defined Variables in your SQL statements.
Example of Connection String:
Database=testdb;Data Source=localhost;User Id=root;Password=hello;Allow User Variables=True