OleDbCommand can't excute this command, Why?
-
19-09-2019 - |
Question
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.
Solution
Maybe these are reserved words. Try quoting them:
SELECT [Input], [Output] FROM PathTable WHERE IP = '127.0.0.1'
OTHER TIPS
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.
It's possible 'input' or 'output' are reserved words in Access SQL so try adding [] square brackets around those field names.
Input and Output may be keywords. Try surrounding them with square brackets. i.e.
[Input] [Output]
File Not Found - Another possible cause of this exception is if the File your trying to load/read does not exist.
I have found it useful to perform a "File.Exists" before trying to open the file just to make sure my code detects this specific cause of the "IErrorInfo.GetDescription failed with E_FAIL(0x80004005)" exception correctly.