OleDbCommand 无法执行此命令,为什么?
我在 MS-Access 数据库中创建一个名为“PathTable”的表。 表格是这样的:
------------------------------
| IP | Input | Output |
------------------------------
| 127.0.0.1 | XXXXX | YYYYYY |
------------------------------
当我编写这些代码时,
String CommandString = "SELECT Input, Output FROM PathTable WHERE IP = '127.0.0.1'";
OleDbCommand CommandObj = new OleDbCommand( CommandString, m_Connection );
OleDbDataReader ReaderObj = CommandObj.ExecuteReader();
代码总是抛出 OleDbException,并且 ErrorDescription 是 E_FAIL(0x80004005),
但是如果我将 commandString 替换为 ,
SELECT * FROM PathTable WHERE IP = '127.0.0.1'
问题就不会再发生了。
所以,我的问题是: OleDbCommand 是否只执行“select * ”?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许这些是保留字。尝试引用它们:
Maybe these are reserved words. Try quoting them:
我正在向您发送 Microsoft 保留字列表,请检查,您正在使用保留关键字,这就是您面临此问题的原因。
http://support.microsoft.com/kb/321266
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
“输入”或“输出”可能是 Access SQL 中的保留字,因此请尝试在这些字段名称周围添加 [] 方括号。
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.Exists”很有用,只是为了确保我的代码正确检测到“IErrorInfo.GetDescription failed with E_FAIL(0x80004005)”异常的特定原因。
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.