I’m writing some helper functions that take a SqlDataReader and process the results. Now normally you’d structure the loop like so:
while(reader.read()){
// Read fields
}
But I my be passing the function a reader which is already positioned on a row, and in this case I want it to process the current row. The code above will only output the entire result set if read() had not been called prior to invoking the function.
I want the function to do something like this:
if(!reader._dataReady)
rowExists = reader.read() // Read
while(rowExists){
// read fields
rowExists = reader.read()
}
_dataReady is an actual member of SqlDataReader and seems to do what I need, however it’s private! Surely there’s a way to determine if the reader is positioned on an actual row, short of trying to read the field and catching the exception.
why not just subclass SqlDataReader, and create Read() method? I have it in all my projects, now: