使用 IDataReader 调用带参数的存储过程
我使用 IDataReader 调用不带参数的存储过程。我没有找到在存在参数时如何执行此操作的示例。 IDataReader 是否处理存储过程的参数?
请举个例子。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我使用 IDataReader 调用不带参数的存储过程。我没有找到在存在参数时如何执行此操作的示例。 IDataReader 是否处理存储过程的参数?
请举个例子。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
它不是处理参数的
IDataReader
,而是IDbCommand
(使用CreateParameter
方法)。然后,您可以使用ExecuteReader
方法。
我整理了一个简单的例子:
It's not the
IDataReader
that deals with parameters, that would be theIDbCommand
(using theCreateParameter
method). Then you can get hold of a reader for the command using theExecuteReader
method.I put together a simple example:
如果您使用企业库,这种风格将非常适合您:
If you're using the Enterprise Library, this style will work well for you:
某些 .NET 提供程序在命令生成器实现中具有静态
DeriveParameters()
方法。如果是这样,您可以使用它来检索参数列表,然后填写值。它提供了一种“发现”信息的好方法:Some .NET providers have a static
DeriveParameters()
method in the command builder implementation. If so, you can use that to retrieve the list of parameters and then fill in the values. It provides a nice way of "discovering" the information:下面的示例对我有用(仅传递参数名称。我只尝试过字符串参数)
Below sample has worked for me (passing the parameter name only. I have only tried this for string parameters)