Search code examples
.netvb.netdatareader

Is there a way to tell if a DataReader has been iterated through without calling .Read()?


Let's say I return a DataReader and completely iterate through it using this code:

While Reader.Read
    Dim x as string = Reader.GetString("x")
End While

I would like to be able to determine whether or not it has been iterated through after the While loop without calling .Read(). The reason why is because .Read() automatically advances to the next row when it is called. If there is a circumstance where the reader hasn't completely been iterated through, I don't want it to advance to the next row. It seems there would be some way to tell if a reader has been fully read.


Solution

  • Per Steve in the question's comments, it looks like this is a duplicate:

    How to detect EOF on DataReader in C# without executing Read()

    Since Steve doesn't want to put his comment at the answer, I am answering my own question with this link. I would delete the question, but se won't let me since it has answers. I won't want this to affect my question/answer ratio, so here we are.