如何使DataReader从一开始就再次开始读取条件? [英] How to make DataReader start reading again from the beginning at a condition?
本文介绍了如何使DataReader从一开始就再次开始读取条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让 dr.Read();
从头开始复读,如果条件得到满足?
是这样的:
SqlDataReader的博士= Command.ExecuteReader却();
的for(int i = 0; dr.Read();我++){
如果(条件){
//让dr.Read()从头开始
阅读}
}
解决方案
您不能。
的
*的DataReader
类的只进的迭代器。
相反,你可以将结果保存在列表< T>
(或数据表
)
How to make dr.Read();
start reading again from the beginning if a condition is satisfied?
Something like:
sqlDataReader dr = command.ExecuteReader();
for(int i=0; dr.Read() ; i++){
if(condition ){
//let dr.Read() start reading from the beginning
}
}
解决方案
You can't.
The *DataReader
classes are forward-only iterators.
Instead, you can store the results in a List<T>
(or a DataTable
)
这篇关于如何使DataReader从一开始就再次开始读取条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文