如何创建一个可以将 SQLDataReader 和 DBDataRecord 作为参数的函数?

发布于 2024-07-24 12:04:08 字数 829 浏览 8 评论 0原文

我有一个通常在 SqlDataReader 内部循环时调用的函数,该函数将从该 SqlDataReader 中获取数据并用它做一些事情。

现在,我还需要能够从 Data Bound Repeater 对象内部调用它,该对象也绑定到 SqlDataReader...

在 DataBound 控件中的“OnDataBinding”事件中,当绑定到DataSet:

RepeaterItem Binder  = (RepeaterItem) Me.NamingContainer;
DataRowView rowResult = (DataRowView) Binder.DataItem;

现在,由于我绑定到 DataReader,我尝试了:

SqlDataReader rowResult = (SqlDataReader) Binder.DataItem;

它不起作用,因为显然 DataItem 的类型为 DataRecordInternal

我能够将其转换为“DbDataRecord”,并且我可以访问它的值,但是我显然无法将它作为参数传递给需要 SqlDataReader 的函数...

我也找不到它们共同的任何基类或接口,用于参数...

最让我困惑的是以下是如何通过数据绑定将 SqlDataReader“转变为”DbDataRecord。 如果我可以在函数内执行此操作,则可以有 2 个重载:一个重载采用 DbDataRecord 并完成其工作,另一个重载采用 SqlDataReader,将其“转换”为 DbDataRecord,并调用第一个重载。

有什么想法吗?
谢谢!

I have a function that is normally called while looping inside a SqlDataReader, that will take data from that SqlDataReader and do some stuff with it.

Now, I need to be able to also call it from inside a Data Bound Repeater object, that is also bound to a SqlDataReader...

In the DataBound control, in the "OnDataBinding" event, I normally do this, when binding to a DataSet:

RepeaterItem Binder  = (RepeaterItem) Me.NamingContainer;
DataRowView rowResult = (DataRowView) Binder.DataItem;

Now, since I'm binding to a DataReader, I tried:

SqlDataReader rowResult = (SqlDataReader) Binder.DataItem;

And it doesn't work because apparently the DataItem is of type DataRecordInternal

I WAS able to cast it to a "DbDataRecord", and I can access its values, but I obviously can't pass it as a parameter to the function that expects a SqlDataReader...

I also can't find any base class or interface they both have in common, to use for the parameter...

What's puzzling me the most here is how, through the Data Binding, the SqlDataReader gets "turned into" a DbDataRecord. If I could do that inside my function, I could have 2 overloads: One that takes a DbDataRecord and does its job, and one that takes a SqlDataReader, "converts it" into a DbDataRecord, and calls the first overload.

Any ideas?
Thanks!

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

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

发布评论

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

评论(1

泅渡 2024-07-31 12:04:08

也许IDataRecord

Perhaps IDataRecord?

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