I'm trying to figure out how the SqlDataReader works, and this is my
main question:
When SqlCommand.ExecuteReader() is called, are all rows of the query
returned immediately? This would mean the a call to reader.Read() would
just return the first row from the underlying data. Or does a call to
reader.Read() fetch the next row from SqlServer?
I've been digging through a watch of SqlDataReader, and can see that
the reader holds a row of data at a time. I would think it's getting
it's rows from the command, but I really can't find much else.
narshe@gmail.com - 05 Mar 2006 22:39 GMT
Ok. I found out a lot from this article:
http://msdn.microsoft.com/msdnmag/issues/04/06/datapoints/default.aspx
The reader is connected the whole time, and a call to DataReader.Read()
gets the next row from sql server.
I also noticed that ExecuteNonQuery and ExecuteScaler use the
DataReader to get their data. Does this mean there is one internal data
reader being used in SqlCommand, and a call to ExecuteReader just
returns that reader?
Another thing I don't get; what is the purpose of DataReader.Close()?
What exactly does this close? It doesn't close the connection. Does it
just set a flag so that calls to ExecuteReader/Scaler/NonQuery don't
try and start a new command sequence to sql server while in the middle
of one?