I have the following code which does what it's supposed to do:
objSQLCommand = New SqlCommand("select * from table1", objSQLConnection)
objSQLCommand.Connection.Open()
objSQLDataReader = objSQLCommand.ExecuteReader()
While objSQLDataReader.Read()
objStringBuilder.Append(objSQLDataReader("forename"))
objStringBuilder.Append("<br /><br />")
objStringBuilder.Append(objSQLDataReader("surname"))
objStringBuilder.Append("<br /><br />")
End While
objSQLDataReader.Close()
objSQLCommand.Connection.Close()
But I need to loop through the objSQLDataReader 1 more time. How would I do that?
Three options:
I'd probably aim at the last option, as it involves no buffering or repetition; however I would move the logic for each method into 2 distinct methods
Loop through data reader only once and load your data into some sort of an instantiated collection (e.g. List<MyDataObject>
) that you can reference later to loop through again and again, and again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With