使DbDataReader从结果集的开头再次开始读取 [英] Make DbDataReader start reading again from the beginning of the result set

查看:159
本文介绍了使DbDataReader从结果集的开头再次开始读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果满足条件,如何使 dr.Read(); 从头开始重新读取?

How to make dr.Read(); start reading again from the beginning if a condition is satisfied?

类似这样的东西:

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

Instead, you can store the results in a List<T> (or a DataTable)

这篇关于使DbDataReader从结果集的开头再次开始读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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