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
I need to iterate twice through a DataReader. Is there a way to do
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.