【发布时间】:2023-03-26 20:05:01
【问题描述】:
每当我运行此查询时,我都会收到此错误。 感谢您的帮助。
{"操作数类型冲突:int 与文本不兼容"}
这是我的代码:
SqlCommand cmd1 = cons.CreateCommand();
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "update coffeeshop set Quantity=convert(varchar(MAX),Quantity)-" + t1.Text;
cmd1.ExecuteNonQuery();
如果我拿走 convert(varchar(Max),如下面的代码所示:
SqlCommand cmd1 = cons.CreateCommand();
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "update coffeeshop set Quantity=Quantity-" + t1.Text;
cmd1.ExecuteNonQuery();
然后我得到这个错误:
{"操作数类型冲突:文本与 int 不兼容"}
【问题讨论】:
-
你表中
Quantity的类型是什么?另外,t1.Text的值是多少? -
数量类型是我的数据库表中的文本,t1.text 的值取决于用户,因为这是一个空文本框,供用户插入一个数量,然后在我的查询中减去它可以看到。