How do I convert a DataTable to an IDatareader?

后端 未结 4 1421
南旧
南旧 2021-02-07 19:03

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 DataTab

4条回答
  •  死守一世寂寞
    2021-02-07 19:59

    A DataReader is the fastest way to read a datastore, but only if certain conditions are met:

    1. The data is to be read in a forward-only manner.
    2. The data is to be read-only.

    Even if these conditions are met by your scenario, the DataReader represents a Connected Datastore, which means that you would need to keep your connection open throughout the time that the DataReader is passed over the network and until the called method at the other end returns some sort of response.

    Therefore, it is my opinion that an active DataReader should never be passed around through various layers and applications. I would much rather extract the data into another data store or collection first and dispose of the DataReader immediately.

提交回复
热议问题