Friday, March 23, 2012

Inexplicable Invalid Syntax error

I created a DB in Access.. then I converted it to work with SQL Server. I have several tables and queries that are working just fine with it.

However, the other day I made a few changes to one of the tables ( Order table), and it seems no matter what kind of query I do with it, it always returns this error:

Invalid syntax near the keyword 'Order'

The query is IDENTICAL to about 10 others like it.. but no matter what kind of query I do to this Order table.. it always returns the same error. I've stepped through it, looked at the query builder, and there's nothing wrong with the format. Here is what the code looks like..

strSQL = "SELECT OrderId FROM Order WHERE SessionId = '"
+ "testfudgeddata" + "' ";
cm.CommandText = strSQL;
dr = cm.ExecuteReader();

while( dr.Read() )
{
orderId = dr.GetInt32(0);
}

It always fails when ExecuteReader() gets called.. with the same error. The syntax is exactly the same as many other queries.. and I even typed in 'testfudgeddata' into the db directly. I am thinking this problem might be related to some proxy-type information that I need to clean out due to the change of the name of this table since it was created in Access.. anyone ever see anything like this?

BrentORDER is a reserved word in SQL Server. change the table name (!)|||Try placing the table name in square brackets.|||AAAAK!

It seems every time I ask for help, I figure out the problem right after. I ran Query Analyzer and was a little confused why my Order table text was blue.. and the other tables were black.

Order is KEYWORD!! DUH!!

Anyways, it's a little funny I guess.. hope you can all get a good laugh from my misery.. heh|||Thanks for the reply guys.. looks like all 3 of us posted at exactly the same time. ;)sql

No comments:

Post a Comment