DataReader cursor rewind

How do I rewind the cursor in the DataReader to the beginning?

With one DataReader result, I need to run two loops while

, but they must be from the beginning. These are two iterations on the same result set that runs the query once.

Example:

dr = command.ExecuteReader(cmd);

while (dr.Read()) { 
    // do some...
}

// rewind cursor here

while (dr.Read()) {
    // do another things...
}

      

I looked through the DataReader docs and found nothing, so if this is not possible with the DataReader, I can change the class to one that suits the purpose.

+3


source to share


1 answer


You can't (unless you run the command again): it's a one-way stream. If you want to see the data more than once, you will have to buffer it in memory yourself, like in List<T>

(for some T

) or (yeuch) like DataTable

.



+3


source







All Articles