DataReader的光标退 [英] DataReader cursor rewind
问题描述
我怎么能倒回一个DataReader的光标的开始?
How do I can rewind a cursor of a DataReader to the beginning?
用一只DataReader的结果,我需要运行两个,而
循环,但这些都必须从头。他们是一个结果两次迭代集运行查询一次
With one DataReader result I need to run two while
loop, but those have to be from beginning. They are two iterations in one result set running a query once.
例如:
dr = command.ExecuteReader(cmd);
while (dr.Read()) {
// do some...
}
// rewind cursor here
while (dr.Read()) {
// do another things...
}
我看着DataReader的文档和我什么也没找到,因此,如果它不能与DataReader的可能,我可能会改变类一个适合此目的。
I've looked into the DataReader docs and I've found nothing, so if it can't be possible with DataReader, I may change the class for one that fits this purpose.
推荐答案
您不能(除非你再次执行该命令):它是单向流。如果你想看到不止一次的数据越多,你就会有缓冲它在内存中自己,例如列表< T>
(对于某些 T
),或(yeuch)为数据表
。
You cannot (unless you execute the command again): it is a one-way stream. If you want to see the data more than once you'll have to buffer it in memory yourself, for example in a List<T>
(for some T
), or (yeuch) as a DataTable
.
这篇关于DataReader的光标退的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!