如果满足某个条件,如何使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
类是“只能向前”迭代器。
相反,你可以将结果存储在List<T>
(或DataTable
)中。
您可以通过首先使用dr.close();
关闭数据读取器,然后再次初始化它来实现。
If(condition)
{
dr.close();
dr=command.ExecuteReader();
}
这里的“command”是MySqlCommand
对象。
ExecuteReader()
获取一个新的读取器。
DataReader
是只能向前读取的。 - Adrian Godong