Using the DataReader
Object
The DataReader
object represents the results of a database query. You get a DataReader
by calling a Command
object’s ExecuteReader()
method.
You can verify whether a DataReader
represents any rows by checking the HasRows
property or calling the Read()
method. The Read()
method returns true
when the DataReader
can advance to a new row. (Calling this method also advances you to the next row.)
The DataReader
represents a single row of data at a time. To get the next row of data, you need to call the Read()
method. When you get to the last row, the Read()
method returns False
.
There are multiple ways to refer to the columns returned by a DataReader
. For example, imagine that you use a SqlDataReader
named reader to represent ...
Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.