清除 OleDbDataReader 参数

发布于 2024-08-16 05:28:50 字数 427 浏览 3 评论 0原文

为了完成我的工作,我查询数据库 (Access) 以查看我的数据是否已经存在。 所以,我正在使用 OleDbDataReader。此刻一切都很好。

接下来,根据查询的结果,我将进行插入或更新。 问题是,此操作使用与我在第一个查询中使用的相同参数 (OleDbParameters)。

因此,当我尝试将这些参数添加到命令中时,我收到此错误:

OleDbParameter 已包含在另一个 OleDbParameterCollection 中

我尝试了一切方法来清除这些参数: - 关闭 OleDbDataReader - 在 OleDbDataReader 上进行处理 - myOleDbDataReader = null

但似乎没有任何效果。

有人有什么想法吗?

多谢。

In order to do my stuff, I query the database (Access) to see if my data is already there.
So, I'm using a OleDbDataReader. Everything is fine at this moment.

Next, depending on the result of my query, I'm doing an insert or and update.
The problem is, this operation is using the same parameters (OleDbParameters) that I was using for my first query.

So when I'm trying to add these parameters to the command, I'm getting this error :

The OleDbParameter is already contained by another OleDbParameterCollection

I tried everything to clear those parameters :
- Close on the OleDbDataReader
- Dispose on the OleDbDataReader
- myOleDbDataReader = null

But nothing seems to work.

Anyone has any idea ?

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

拍不死你 2024-08-23 05:28:50

要取消 OleDbParameters 与 OleDbParameterCollection 的关联,您可以使用删除方法 OleDbParameterCollection。作为替代方案,清除方法 将一步对集合中的所有参数执行此操作。

您还应该小心使用带有多个命令的单个连接。您可以在此处找到有关此主题的更多信息。

To disassociate the OleDbParameters from the OleDbParameterCollection you could use the Remove Method on the OleDbParameterCollection. As an alternative, the Clear Method would perform this action for all of the parameters in the collection in one step.

You should also be careful about using a single connection with multiple commands. You'll find more information on this topic here.

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