我似乎无法弄清楚为什么这句话给我带来了问题:
sqlCommand.CommandText = @"INSERT INTO Fulfilled_Shipments_Data (amazon-order-id) VALUES " + lines[0];
我收到错误:
[Error]: There was an error parsing the query. [ Token line number = 1,Token line offset = 44,Token in error = - ]
指向 - 在amazon-order-id中。
当我从visual studio中执行SQL时遇到同样的错误,但我可以使用该列名查询现有数据。
我确信这对于SQL大师来说是一件微不足道的事情,但我正在挠头,所以我们非常感谢您的帮助!
答案 0 :(得分:5)
您需要转义amazon-order-id
,因为它有减号(破折号)。它应该是[amazon-order-id]
:
...INSERT INTO Fulfilled_Shipments_Data ([amazon-order-id])...
此外,值应位于括号中:VALUES (" + lines[0]+")";
最终版本:
sqlCommand.CommandText = @"INSERT INTO
Fulfilled_Shipments_Data ([amazon-order-id])
VALUES (" + lines[0]+")";
答案 1 :(得分:2)
我认为您的SQL语法应如下所示:
sqlCommand.CommandText = @"INSERT INTO Fulfilled_Shipments_Data (amazon-order-id) VALUES ('" + lines[0] + "')";
OR
sqlCommand.CommandText = @"INSERT INTO Fulfilled_Shipments_Data (amazon-order-id) VALUES (" + lines[0] + ")";
取决于amazon-order-id
答案 2 :(得分:1)
尝试这些。
sqlCommand.CommandText = @"INSERT INTO Fulfilled_Shipments_Data (amazon-order-id) VALUES ('" + lines[0]+"')";
OR
sqlCommand.CommandText = @"INSERT INTO Fulfilled_Shipments_Data ([amazon-order-id]) VALUES ('" + lines[0]+"')";