如何将 DataTable 转换为 IDatareader?
我们都知道 DataReader 比 DataTable 更快,因为 DataReader 用于构建 DataTable。
因此,鉴于我已经有一个 DataTable...为什么我要将其转换为 DataReader?
那么我正在创建一个名为 IDataProvider 的内部接口。 该接口旨在本地实现并作为 WebService 实现。 该接口将有一个方法“Getdata”,它接受一些条件信息并返回一些数据。
由于 DataReader 是最快的数据检索机制,因此我希望将其用作“GetData”方法的结果类型。 但是我们也知道 DataReader 不可序列化,因此无法通过 Web 服务在 Web 上传输...
在 Web 的情况下,我会让本地代理类请求数据作为 DataTable,然后将其在本地转换为数据读取器。
通过这种方式,本地应用程序不需要知道(或关心)它是在本地还是远程访问数据。
然而,为了做到这一点,我需要知道... 如何将 DataReader 包装在预先存在的 DataTable 周围?
更新:我的业务逻辑不会保存在 Web 服务中,因为使用的 DataProvider Web 服务可以切换为不支持的 Web 服务。 因此,业务逻辑将保存在客户端应用程序中。
FWIW我正在使用.Net 3.5 SP1
We all know that DataReaders are quicker than DataTables since the a DataReader is used in the construction of a DataTable.
Therefore given that I already have a DataTable.... Why would I want to convert it to a DataReader?
Well I am creating an internal interface called IDataProvider. This interface is intended to be implemented both locally and as a WebService. The interface will have a method "Getdata" which takes some criteria information and returns some data.
Since a DataReader is the quickest data retrieval mechanism, I will want to use this as the result type of the "GetData" method.
However we also know that the DataReader is not serializable and therefore cannot be transferred across the web via a web service...
In the case of the web I would have the local proxy class request the data as a DataTable and then transform it locally into a DataReader.
In this way the Local application need not know (or care) that if it is accessing the data locally or remotely.
However in order to do this I need to know... How do I wrap a DataReader around a preexisting DataTable?
Update: My business logic is not going to be held in the webservice since the DataProvider that uses the Webservice is switchable for one which does not.
The businessLogic will therefore be held in the client app.
FWIW I am using .Net 3.5 SP1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
只需在
DataTable
上调用CreateDataReader()
Just call
CreateDataReader()
on yourDataTable