Converting a datatable to a sqlreader?

  • Thread starter Thread starter Marina
  • Start date Start date
M

Marina

I don't see how you can create a datareader, since that is implicitly tied
to the database. In fact, datatables and datasets, use data readers to
actually get their data.

Why do you need a data reader?
 
You can't convert a Datatable to a reader. A reader only works with an
open database connection and a datatable can't physically connect itself to
a database...the dataadapter actually uses a DataReader and fills the
datatable. If you can't change the existing structure, add another method
that can return a datareader. All in all, they are very very different
objects with different goals and uses. A DataTable can do things a
DataReader can't but a Reader can't do anything a DataTable can't. A
DataReader is faster but that's it. And if you were going to fill a
DataTable anyway, even if a conversino were possible, it would defeat the
only purpose for using a Reader over a DataTable. Since a DataReader is
already used to fill the datatable with the dataadapter, you'd have a
reader, filling a table and then that table would be used to populate a
reader...this would be very inefficient .

With that said, many things can be converted from one to another even though
it's inefficient, but that conversion is impossible. If you have some
other reason, you may want to serialize your dataset to XML using
DataSet.WriteXML("PathName:\FileName.xml") then use an XML Reader to read
the file, but even this is painfully inefficient unless you have a
compelling reason to do so.

HTH,

Bill
 
How does one convert a datatable to a sqlreader? We have a generic backend
that returns datasets or datatables. For sake of brevity assume I can't
change the backend to return a reader. Is there an easy way to do this?

Regards,

Paul
 
Back
Top