c# - .NET MySqlCommand @ 占位符与 MySQL 变量冲突

标签 c# mysql .net vb.net

这是针对此问题的示例 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/

相关文章:

php - 访问mysql数据库中的多个表

.NET CalDAV 客户端

c# - Hashtable 对象还有用吗?

php - 使用PHP在HTML中显示MySQL

c# - Application_Error() 未触发

PHP MYSQL 到 XML - 高效的文件生成

c# - 在 LINQ 中使用求和方法

c# - 如何从数码相机中获取录制的视频?

c# - 按用户定义的顺序将选定的 CSV 文件导入新的 Excel 文件

c# - 使用参数从 DbCommand 获取 SQL 查询字符串