Search code examples
.netdatareader

Iterate twice through a DataReader


I need to iterate twice through a DataReader. Is there a way to do this without using DataSets and without running the query twice? I'm using C#, by the way.
Thanks


Solution

  • The short answer is no, you run through the enumeration for the result sets and then you're done. What should probably be done is to dump the results to some kind of simplified raw results that you can iterate over as much as you want (avoiding the overhead of the DataSet).

    If you take a peek at MSDN, it notes that the SqlDataReader is "forward only" which would suggest again that this isn't possible.