Robert H
Robert H

Reputation: 11730

SQL [Error]: There was an error parsing the query. [ Token line number = 1,Token line offset = 44,Token in error = - ]

I can't seem to figure out why this statement is giving me problems:

sqlCommand.CommandText = @"INSERT INTO Fulfilled_Shipments_Data (amazon-order-id) VALUES " + lines[0];

I am getting error:

[Error]: There was an error parsing the query. [ Token line number = 1,Token line offset = 44,Token in error = - ]

which points to the - in amazon-order-id.

I get the same error when I execute the SQL from within visual studio, however I can query existing data using that column name.

I am sure this is a trivial matter for a SQL guru, but I am scratching my head so any assistance is appreciated!

Upvotes: 0

Views: 7496

Answers (3)

ehsan
ehsan

Reputation: 11

try these .

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]+"')";

Upvotes: 1

a1ex07
a1ex07

Reputation: 37354

You need to escape amazon-order-id because it has minus(dash) sign. It should be [amazon-order-id]:

...INSERT INTO Fulfilled_Shipments_Data ([amazon-order-id])...

Also, values should be in parenthesis :VALUES (" + lines[0]+")";

Final version:

sqlCommand.CommandText = @"INSERT INTO 
Fulfilled_Shipments_Data ([amazon-order-id])
VALUES (" + lines[0]+")";

Upvotes: 5

Barry Kaye
Barry Kaye

Reputation: 7761

I think your SQL syntax should look like this:

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] + ")";

depending on the data type of amazon-order-id

Upvotes: 2

Related Questions