OleDbCommand 无法执行此命令,为什么?

发布于 2024-08-15 10:34:10 字数 747 浏览 8 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

似狗非友 2024-08-22 10:34:10

也许这些是保留字。尝试引用它们:

SELECT [Input], [Output] FROM PathTable WHERE IP = '127.0.0.1'

Maybe these are reserved words. Try quoting them:

SELECT [Input], [Output] FROM PathTable WHERE IP = '127.0.0.1'
水溶 2024-08-22 10:34:10

我正在向您发送 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

醉态萌生 2024-08-22 10:34:10

“输入”或“输出”可能是 Access SQL 中的保留字,因此请尝试在这些字段名称周围添加 [] 方括号。

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

意中人 2024-08-22 10:34:10

输入和输出可以是关键字。尝试用方括号将它们括起来。即

[输入]
[输出]

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

[Input]
[Output]

深海夜未眠 2024-08-22 10:34:10

未找到文件 - 导致此异常的另一个可能原因是您尝试加载/读取的文件不存在。

我发现在尝试打开文件之前执行“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文