我收到的SQLException未被用户代码“TBL'附近的语法错误处理。”我还尝试用表名替换[PrioContextDb]。[dbo]。[RatingListTriangleModels]而没有括号。
using (SqlCommand command = new SqlCommand
("delete from [PrioContextDb].[dbo].[RatingListTriangleModels] TBL where ( TBL.To1Id = @MY_ID and TBL.To2Id = @OTHER_ID ) or ( TBL.To2Id = @My_ID and TBL.To3Id = @OTHER_ID ) or ( TBL.To3Id = @My_ID and TBL.To1Id = @OTHER_ID )", cn))
{
//
// Add new SqlParameter to the command.
//
command.Parameters.Add(new SqlParameter("MY_ID", myToid));
command.Parameters.Add(new SqlParameter("OTHER_ID", theirTradeObjectid));
var no = command.ExecuteNonQuery();
答案 0 :(得分:2)
正如其他人所建议的那样,您需要删除TBL
到您的SQL语句。您还需要将其从所有子句中删除。
但是您的参数看起来似乎缺少@
,这可能是您获得的下一个错误。
command.Parameters.Add(new SqlParameter("@MY_ID", myToid));
command.Parameters.Add(new SqlParameter("@OTHER_ID", theirTradeObjectid));
答案 1 :(得分:1)
请尝试删除别名TBL。
delete from [PrioContextDb].[dbo].[RatingListTriangleModels]
where ( To1Id = @MY_ID and To2Id = @OTHER_ID ) or
( To2Id = @My_ID and To3Id = @OTHER_ID ) or
( To3Id = @My_ID and To1Id = @OTHER_ID )
答案 2 :(得分:-1)
在TBL
关键字之后添加别名DELETE
,如下所示:
delete TBL
from [PrioContextDb].[dbo].[RatingListTriangleModels] TBL
where ...
...