c# - 使用 C# 在 MYSQL 中声明局部变量时发生 fatal error

标签 c# mysql sql

我在 MYSQL 中声明局部变量时遇到异常。请建议我如何解决这个问题..

异常:
命令执行期间遇到 fatal error 。
内部异常:
{“必须定义参数'@OrderofParent'。”}

代码片段:

   StringBuilder sbQuery = new StringBuilder(); <br>
    sbQuery.Append(@"Declare @OrderofParent INT; SET @OrderofParent = 0;
                    select top 1 @OrderofParent = OrderofParent from Filter group        by          OrderofParent order by OrderofParent desc;

    select 'FamilyType' as Mode, 0 as Id, 'Complexity Type' as FilterName, null as FilterCreatedDate, 0 as IsDisabled,0 as ParentId,                                               @OrderofParent as OrderofParent,1 as TagDisplay, 0 as ParentCount from I_FamilyTypePrice
union
Select 'Filter', Id, FilterName, FilterCreatedDate, IsDisabled, f.ParentId, OrderofParent, TagDisplay, 0 from Filter f where f.ParentID = 0 
union
select 'FamilyType', ft.Id, FamilyTypeName, CreatedDate, 0,0, @OrderofParent,0, count(complexityType) from I_FamilyTypePrice ft join Family f on f.complexityType = ft.Id where version = @version and IsActive = 1 and Uploaded = 1; ");

最佳答案

添加 “允许用户变量=True” 在连接字符串参数中

关于c# - 使用 C# 在 MYSQL 中声明局部变量时发生 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21619164/

相关文章:

python - 从 sqlalchemy mixins 继承并添加索引

java - 具有两个抽象类的 JPA 继承

java - 何时关闭带有 DAO 模式的 SQL 连接?

php - 使用 PHP 在 MySQL 中搜索完全匹配的单词

c# - 分钟内的 Hangfire 重复任务

c# - REQ/REP 模式中的 ZeroMQ FiniteStateMachineException

mysql - 如果日期在相邻小时内,则合并日期

sql - 在 Snowflake 中使用正则表达式过滤与句子/单词的完全匹配

javascript - 从代码隐藏向 jQuery 函数发送动态参数

c# - 在IIS上托管的C#中使用USB token 打开X509证书选择