尝试在 C# 中递增 SQL 行时查询失败
Query fails when trying to Increment SQL Row in C#
我基本上是在尝试在运行时将行值从“24”增加到“25”。但是查询失败并产生了这个错误:
Conversion failed when converting the varchar value 'Views + 1' to data type int.
查询:
update posttable
set Views = 'ISNULL(Views, 0) + 1'
where id = '379698'
该列的类型为 int
而不是 varchar
。为什么会失败?
去掉引号
update posttable set Views=Views + 1 where id='379698'
我基本上是在尝试在运行时将行值从“24”增加到“25”。但是查询失败并产生了这个错误:
Conversion failed when converting the varchar value 'Views + 1' to data type int.
查询:
update posttable
set Views = 'ISNULL(Views, 0) + 1'
where id = '379698'
该列的类型为 int
而不是 varchar
。为什么会失败?
去掉引号
update posttable set Views=Views + 1 where id='379698'