tags:

views:

31

answers:

3

Does the read method just position itself to next record? or it actually reads the record?

lets say i call read 1000 times, does it actually get all values of that each records? or its when I call GetValue?

+1  A: 

Yes, it reads the record data into a local (client) buffer. Then GetValue() finds it in that buffer and hands it to you.

Your question seems to be asking "can I get to record #1000 without moving the first 999 rows of data from the DBMS to the client", in which case: not this way.

Edit

When I can't implement paging in the queries or in a stored procedure (which is often the case), and the data-per-row is large, I make the query return the absolute minimum data (such as a primary key) and fetch the rows one by one.

egrunin
yeah, it's exactly it, trying to move to a certain position and starts reading X number of record. Basically trying to implement data paging with datareader.
pdiddy
Interesting approach for the pk, thanks. But I think I'll have to go with the stored procedure.
pdiddy
+2  A: 

The read method advances to the next record and retrieves the data, so when you call GetValue, the data is ready and waiting for you.

davisoa
A: 

Just what it does is implementation-defined. However, considering normal usage, by far the most efficient method would be to get all 1000 rows from the database. Granted that's less efficient when you aren't using the data in those rows, but consider the alternative where it obtained each row separately and then imagine the impact when you did use those rows.

Jon Hanna