如何创建一个可以将 SQLDataReader 和 DBDataRecord 作为参数的函数?
我有一个通常在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许
IDataRecord
?Perhaps
IDataRecord
?