通过一个DataReader迭代两次 [英] Iterate twice through a DataReader
问题描述
我需要通过一个DataReader迭代两次。有没有办法做到这一点,而无需使用数据集,并没有运行查询两次?我使用C#,顺便说一句。
谢谢
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
推荐答案
简短的回答是否定的,你通过枚举的结果集运行,然后就大功告成了。什么也许应该做的是结果转储到某种简单的原始结果,你可以遍历,只要你想(避免DataSet的开销)为多。
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).
如果你把偷看的 MSDN ,它指出,SqlDataReader的是只向前,这将再次表明,这是不可能的。
If you take a peek at MSDN, it notes that the SqlDataReader is "forward only" which would suggest again that this isn't possible.
这篇关于通过一个DataReader迭代两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!