[英]{“Operand type clash: int is incompatible with text”}
Whenever I run this query I get this error. 每当我运行此查询时,都会出现此错误。 Help is appreciated.
感谢帮助。
{"Operand type clash: int is incompatible with text"}
{“操作符类型冲突:int与文本不兼容”}
this is my code: 这是我的代码:
SqlCommand cmd1 = cons.CreateCommand();
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "update coffeeshop set Quantity=convert(varchar(MAX),Quantity)-" + t1.Text;
cmd1.ExecuteNonQuery();
If I take away the convert(varchar(Max) as it can be seen in code bellow: 如果我删除了convert(varchar(Max),如下面的代码所示:
SqlCommand cmd1 = cons.CreateCommand();
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "update coffeeshop set Quantity=Quantity-" + t1.Text;
cmd1.ExecuteNonQuery();
Then I get this error: 然后我得到这个错误:
{"Operand type clash: text is incompatible with int"}
{“操作数类型冲突:文本与int不兼容”}
Try this out assuming quantity is varchar
: 假设数量为
varchar
请尝试以下方法:
cmd1.CommandText = "update coffeeshop set Quantity= Convert(int,Quantity)-" + t1.Text;
for text
try this: 对于
text
尝试以下操作:
cmd1.CommandText = "update coffeeshop set quantity= Convert(varchar(max) , Convert(INT, Convert(varchar(max),quantity))- "+ t1.Text + ")";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.