SQLDataReader

  • Thread starter Thread starter Dom
  • Start date Start date
D

Dom

In the old days, using ADO, I used to be able to move up and down in a
resultset, but using functions like MoveNext, MoveFirst, MoveLast,
MovePrev. I don't see any of that in the SQLDataReader object. It
seems I can only move through it sequentially. Is that true?

Dom
 
Dom,

Yes, that is true. The SqlDataReader (or any class that derives from
DbDataReader, really) is meant for forward-only, read-only access.

If you want to move through a set of data, then you will need to load
the data into a DataTable, through a DbDataAdapter derivative (in this case,
SqlDataAdapter) and then you can cycle through the rows in any way that you
wish.

Mind you that doing it in this way is going to be the equivalent of
setting the cursor location on an ADODB Recordset to adUseClient, and then
loading the data statically (adOpenStatic). Basically, the DataTable is an
in-memory representation of the result set.
 
Thanks for clarifying this. BTW, you've answered so many of my
questions, I feel like you're my private tutor.

Dom



Dom,

Yes, that is true. The SqlDataReader (or any class that derives from
DbDataReader, really) is meant for forward-only, read-only access.

If you want to move through a set of data, then you will need to load
the data into a DataTable, through a DbDataAdapter derivative (in this case,
SqlDataAdapter) and then you can cycle through the rows in any way that you
wish.

Mind you that doing it in this way is going to be the equivalent of
setting the cursor location on an ADODB Recordset to adUseClient, and then
loading the data statically (adOpenStatic). Basically, the DataTable is an
in-memory representation of the result set.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




In the old days, using ADO, I used to be able to move up and down in a
resultset, but using functions like MoveNext, MoveFirst, MoveLast,
MovePrev. I don't see any of that in the SQLDataReader object. It
seems I can only move through it sequentially. Is that true?
Dom- Hide quoted text -

- Show quoted text -
 
Can I send you a bill? =) J/K


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dom said:
Thanks for clarifying this. BTW, you've answered so many of my
questions, I feel like you're my private tutor.

Dom



Dom,

Yes, that is true. The SqlDataReader (or any class that derives from
DbDataReader, really) is meant for forward-only, read-only access.

If you want to move through a set of data, then you will need to load
the data into a DataTable, through a DbDataAdapter derivative (in this
case,
SqlDataAdapter) and then you can cycle through the rows in any way that
you
wish.

Mind you that doing it in this way is going to be the equivalent of
setting the cursor location on an ADODB Recordset to adUseClient, and
then
loading the data statically (adOpenStatic). Basically, the DataTable is
an
in-memory representation of the result set.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




In the old days, using ADO, I used to be able to move up and down in a
resultset, but using functions like MoveNext, MoveFirst, MoveLast,
MovePrev. I don't see any of that in the SQLDataReader object. It
seems I can only move through it sequentially. Is that true?
Dom- Hide quoted text -

- Show quoted text -
 
Back
Top