Make DbDataReader start reading again from the beginning of the result set

后端 未结 3 1099
旧巷少年郎
旧巷少年郎 2021-01-17 09:57

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

Something like:

SqlDataReader dr = command.Ex         


        
相关标签:
3条回答
  • 2021-01-17 10:41

    You can't.

    The *DataReader classes are forward-only iterators.

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

    0 讨论(0)
  • 2021-01-17 10:46

    The only way to restart it is to grab a new reader with ExecuteReader().

    0 讨论(0)
  • 2021-01-17 11:00

    You can do that by first closing the datareader using dr.close(); then initializing it again.

    If(condition)
    {
        dr.close();
        dr=command.ExecuteReader();
    }
    

    Where command is the MySqlCommand object.

    0 讨论(0)
提交回复
热议问题