使用c#在MySQL中进行参数转义
本文关键字:参数 转义 MySQL 使用 | 更新日期: 2023-09-27 17:53:00
我有一个像这样的c#存储过程创建代码....
string query="CREATE PROCEDURE `MyProc`(IN `searchText` text, IN `iterationsCount` INT, IN `filterName` char(30))
BEGIN
DECLARE i INT;
SET i = 1;
SET @sSelectBilling = 'count(distinct t.BillingID) from Billing t';
.....
.....
END"
当我尝试创建这个sp通过c#使用MySQLCommand.ExecuteNonQuery();参数'@sSelectBilling'必须被定义。如何解决这个问题?
试试这个
CREATE PROCEDURE `MyProc` (
`searchText` text,
`iterationsCount` INT,
`filterName` char(30) )
BEGIN
DECLARE i INT;
DECLARE @sSelectBilling INT; // define your variable here.
SET i = 1;
SET @sSelectBilling = (count(distinct t.BillingID) from Billing t);//use () instead of quotes.
我自己想出来的。我需要添加允许用户变量=true;在连接字符串中。下面的文章帮我弄明白了http://markcordell.blogspot.com/2008/12/calling-mysql-stored-procedures-from-c.html