【发布时间】:2017-09-12 07:59:35
【问题描述】:
我对这个 MySQL 命令有疑问:
cmdTemp = New MySqlCommand("SET @qty = " & Qty & "; update(tb_harvest) set actual = (case when @qty >= actual " & _
"then if(@qty := @qty - actual, 0, 0) when (@tmp := actual - @qty) " & _
"then if(@qty := 0, @tmp, @tmp) " & _
"else actual end), Status = (case when @qty >= actual then if(@qty := @qty - actual, 0, 0) " & _
"when (@tmp := actual - @qty) then if(@qty := 0, 1, 1) else 1 end) order by harvestid;", cn)
当我尝试在 VB.NET (VS2008) 中运行时,出现以下错误:
@Qty必须定义,@tmp也是如此
但是,当我在 MySQL(HeidiSQL) 上运行它时,它没有问题。
当我添加到New ConnectionString,Allow User Variables = true 时,错误是:
不支持关键字。参数名称:allowuservariables
这是我的ConnectionString,我使用Connection Strings 组合在一起:
Server=localhost;Port=3306;Database=testing;Uid='test';Pwd='test';AllowUserVariables=True;
我正在使用 MySQL 5.6.21 版
【问题讨论】:
-
我会说去掉查询的
Set @qty部分,然后将参数添加到名为@qty的cmdTemp.Parameters集合中。 -
请帮我解决这个问题!,即使我已经在使用
cmdTemp.Parameters它仍然给我和错误@ChrisDunaway -
不清楚您要做什么。
IF函数内部赋值的目的是什么? -
我试图完成的是当按下按钮时,它运行上面的代码。在数据库中,数量值从第一行更新每一行,直到输入的数量达到 0。例如:
Qty = 500row 1 qty=300row 2 qty=400如果代码运行Row 1 qty = 0 and row 2 qty = 200清除? @ChrisDunaway -
使用
@,这个@Bugs 没有错