|
Notice the call to Read on the SqlDataReader, rdr, in the while loop condition in the example code shown above. The return value of Read is the type bool and returns true as long as there are more records to read. After the last record in the data stream has been read, Read returns the false value.
In previous Tutorial, we extracted the first column from the row by using a SqlDataReader indexer(rdr[0]). You can extract each column of the row with a numeric index like this, but it is not very readable. The example above uses a string indexer, where the string is the column name from the SQL query the table column name if you used an asterisk, *. String indexers are much more readable, making the code easier to maintain.
|