Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best method for Populating DataSet from a SQLDataReader

I am working on a DAL that is getting a DataReader Asynchronously.

I would like to write a single method for transforming the DataReader into a DataSet. It needs to handle different schema so that this one method will handle all of my fetch needs.

P.S. I am populating the SQLDataReader Asynchronously, please don't give answers that are getting rid of the DataReader.

like image 359
Andrew Harry Avatar asked Feb 04 '09 05:02

Andrew Harry


2 Answers

DataTable.load() can be used for a generic approach.

do {
    var table = new DataTable();
    table.Load(reader);
    dataset.Tables.Add(table);
} while(!reader.IsClosed);
like image 187
Peter Riesz Avatar answered Sep 20 '22 13:09

Peter Riesz


Try DataSet.Load(). It has several overloads taking an IDataReader.

like image 29
Matt Hamilton Avatar answered Sep 18 '22 13:09

Matt Hamilton