如何转换一个DataTable一个IDataReader的? [英] How do I convert a DataTable to an IDatareader?

查看:968
本文介绍了如何转换一个DataTable一个IDataReader的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道的DataReader比,因为一个DataReader被用在一个DataTable的建设的DataTable更快。

We all know that DataReaders are quicker than DataTables since the a DataReader is used in the construction of a DataTable.

因此​​,考虑到我已经有一个DataTable .... 为什么我想将其转换为一个DataReader?

Therefore given that I already have a DataTable.... Why would I want to convert it to a DataReader?

嗯,我正在创建一个名为IDataProvider内部接口。这个接口旨在被本地和作为一个WebService实现。该界面将有一个方法GETDATA这需要一些条件的信息,并返回一些数据。

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.

由于一个DataReader是最快的数据检索机制,我想用这个作为的GetData方法的结果类型。 但是我们也知道,DataReader的是不可序列化,所以不能在网上通过Web服务传输...

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...

在网络的情况下,我会对当地代理类的请求的数据作为一个DataTable,然后在本地把它变成一个DataReader。

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.

不过,为了做到这一点,我需要知道... 如何包装一个preexisting的DataTable围绕一个DataReader?

However in order to do this I need to know... How do I wrap a DataReader around a preexisting DataTable?

更新:我的商业逻辑是不会在web服务举行,因为使用web服务的dataProvider是切换的一种不。 该businessLogic因此将在客户端应用程序进行。

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我使用.NET 3.5 SP1

FWIW I am using .Net 3.5 SP1

推荐答案

只需拨打CreateDataReader你的数据表

Just call CreateDataReader on your DataTable

这篇关于如何转换一个DataTable一个IDataReader的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆