For Performance improvement I want to convert datatable to datareader. I can not do that through query. So is there any other way to do so?
Create a DataTable schema in the destination DataSet using the schema information returned by the GetSchemaTable ( ) method of the DataReader . Then, use the GetData ( ) method of the DataReader to load each row of data into an array of objects, and add it to the DataTable using the Add ( ) method of the contained DataRowCollection .
You need to transfer data from a DataReader to a DataSet . Create a DataTable schema in the destination DataSet using the schema information returned by the GetSchemaTable ( ) method of the DataReader .
Performance wise a data reader is faster than any of the other way like data adapter and cell set in MDX result. So in few situations you may need to convert this data reader to a data table. Here in this post we will discuss how we can convert it.
A DataReader is typically used to read data from the database and add logic to fill a list of objects or a DataTable. So it's best to do most business logic which has to do with the building of the DataTable on the webservice, pass it to the client as a webservice and work with the other ADO.Net functions there for more business logic.
I know this is old, but the answers here seem to have missed the point of the OPs question.
DataTables have a method called CreateDataReader which will allow you to convert a DataTable to a DbDataReader object. In this case a DataTableReader.
DataTable table = new DataTable();
//Fill table with data
//table = YourGetDataMethod();
DataTableReader reader = table.CreateDataReader();
I should point out that this will not increase performance since you should be using one or the other.
Here are some more resources on the matter:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With