这是针对此问题的示例 SQL。 (实际的SQL比这个复杂多了)
SET @HELLO = 1;
SELECT @HELLO;
如您所见。 @HELLO
是一个 MySQL 变量,但 .NET MySQLCommand 将其视为占位符而不需要绑定(bind)值。无论如何,我可以在 .NET 中使用 MySQL 变量吗?
最佳答案
看看下面的MySql.Data.MySqlClient.MySqlException: Parameter ‘@id’ must be defined
哪个州
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
关于c# - .NET MySqlCommand @ 占位符与 MySQL 变量冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18071778/