如果满足条件,如何dr.Read();从头开始阅读?
就像是:
SqlDataReader dr = command.ExecuteReader();
for(int i=0; dr.Read() ; i++){
if(condition ){
//let dr.Read() start reading from the beginning
}
}
如果满足条件,如何dr.Read();从头开始阅读?
就像是:
SqlDataReader dr = command.ExecuteReader();
for(int i=0; dr.Read() ; i++){
if(condition ){
//let dr.Read() start reading from the beginning
}
}
你不能。
这些*DataReader类是只进迭代器。
相反,您可以将结果存储在 a List<T>(或 a DataTable)中
重新启动它的唯一方法是使用ExecuteReader().
您可以通过首先使用关闭数据读取器dr.close(); 然后再次对其进行初始化来做到这一点。
If(condition)
{
dr.close();
dr=command.ExecuteReader();
}
其中 command 是MySqlCommand对象。