How does a DataReader work ?

  • Thread starter Thread starter Guest
  • Start date Start date
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 ?.
 
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.
 
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 ?.
 
Back
Top