views:

89

answers:

5

I create a table named "PathTable" in a MS-Access DB. The table is like this:

------------------------------
| IP        | Input | Output |
------------------------------
| 127.0.0.1 | XXXXX | YYYYYY |
------------------------------

When I programed these

String CommandString = "SELECT Input, Output FROM PathTable WHERE IP = '127.0.0.1'";

OleDbCommand CommandObj = new OleDbCommand( CommandString, m_Connection );

OleDbDataReader ReaderObj = CommandObj.ExecuteReader();

the code always throw OleDbException, and the ErrorDescription is E_FAIL(0x80004005),

But if I replaced the commandString with

SELECT * FROM PathTable WHERE IP = '127.0.0.1'

The problem never happended again.

So, my question is: Does OleDbCommand only excute "select * "? Thanks.

+2  A: 

Maybe these are reserved words. Try quoting them:

SELECT [Input], [Output] FROM PathTable WHERE IP = '127.0.0.1'
Darin Dimitrov
Won't that treat them as string literals Darin?
Chris Arnold
You are right. Square brackets should be used.
Darin Dimitrov
Do I get partial credit? :)
Chris Arnold
Thank you, Darin. "Input" and "Output" are MS-Access reserved words indeed.But I've never known.
Jollian
Is it not true that an alternative to the brackets (which are evil and will break the standard Access SQL 89 implementation of derived tables) is to fully qualify the fields, i.e., "SELECT PathTable.Input, PathTable.Output"?
David-W-Fenton
@David W. Fenton: Access's ANSI-89 Query Mode's implementation of derived tables is itself evil. Note that "SQL-89" refers to a SQL Standard' and that the Access parlance is ANSI-89. Also note that Standard SQL uses double quotes (ascii code 0034) rather than square brackets to escape keywords so alluding to SQL Standards here is inappropriate.
onedaywhen
A: 

It's possible 'input' or 'output' are reserved words in Access SQL so try adding [] square brackets around those field names.

Tony Toews
Not only Access SQL but ODBC and ISO/ANSI Standard SQL from SQL-92 onwards.
onedaywhen
A: 

Did you try "SELECT [Input], [Output] FROM PathTable WHERE IP = '127.0.0.1'";?

derans
A: 

Input and Output may be keywords. Try surrounding them with square brackets. i.e.

[Input] [Output]

Chris Arnold
+1  A: 

I am sending you the list of Microsoft reserved words, Please check, you are using reserved keyword that's why you are facing this problem.

http://support.microsoft.com/kb/321266

Pankaj