DataReader Question

  • Thread starter Thread starter timothy
  • Start date Start date
T

timothy

Hi,

I am trying to decide to use a datareader to retrieve data from MS SQL
Server or use a dataset. I have seen examples retrieve the data using a
reader then loop through the reader and load it into a dataset. Is it
saving that much more time than filling a dataset?

Thanks
 
timothy said:
Hi,

I am trying to decide to use a datareader to retrieve data from MS SQL
Server or use a dataset. I have seen examples retrieve the data using a
reader then loop through the reader and load it into a dataset. Is it
saving that much more time than filling a dataset?

No. That's exactly what the DataAdapter does behind the scenes.

David
 
Like David mentions, an DataReader is utilized to fill the table. You'll
notice the frequency of the word Reader is Dbexceptions if you examine the
stack trace...that's b/c they are used everywhere underneath.

You could certianly do this, but you'll be writing a lot of code that's
already been written and tested.

John Papa just laid it all out though in MSDN Magazine...
http://www.msdn.microsoft.com/msdnmag/issues/04/06/DataPoints/default.aspx

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
It's not so much about time as it is about memory. A DataReader does not
create copies of your data (as you would have in a DataSet). This is why
you must loop through the DataReader as it is iterating over each record
from the actual DataSource and is not holding all the records in memory.
 
Back
Top