How does a DataReader work ?

G

Guest

Hi
I have a question on how the datareader work underneath when retrieving the records from the data source
Does the DataReader fetch one row of data everytime I call the Read() method or all the rows for the query is available in memory before I call Read() method ?.
 
J

Jon Skeet [C# MVP]

Sreeharsha said:
I have a question on how the datareader work underneath when
retrieving the records from the data source. Does the DataReader
fetch one row of data everytime I call the Read() method or all the
rows for the query is available in memory before I call Read() method?

I think that partly depends on what CommandBehavior you're using. If
you ask for SequentialAccess, it shouldn't read the whole row in at
once. Otherwise, it may well do.
 
S

Sushil Chordia

DataReader is basically a fire-hose cursor (ie) it allows data to be pulled
from a stream. DataReader does not fetch one row at a time, instead it gets
the data in packets and reads the next packet from the wire when necessary.
If you are interested to have all the data in memory you should probably use
a disconnected data model in ADO.NET which is the DataSet. Datareaders are
used for high performance read only access.

Hope that helps,
Sushil.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Sreeharsha said:
Hi,
I have a question on how the datareader work underneath when retrieving
the records from the data source.
Does the DataReader fetch one row of data everytime I call the Read()
method or all the rows for the query is available in memory before I call
Read() method ?.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top