DataReader的光标退 [英] DataReader cursor rewind

查看:285
本文介绍了DataReader的光标退的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能倒回一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆