SqlDataReader::Read Method ()
Advances the SqlDataReader to the next record.
Assembly: System.Data (in System.Data.dll)
| Exception | Condition |
|---|---|
| SqlException | SQL Server returned an error while executing the command text. |
The default position of the SqlDataReader is before the first record. Therefore, you must call Read to begin accessing any data.
Only one SqlDataReader per associated SqlConnection may be open at a time, and any attempt to open another will fail until the first one is closed. Similarly, while the SqlDataReader is being used, the associated SqlConnection is busy serving it until you call Close.
The following example creates a SqlConnection, a SqlCommand, and a SqlDataReader. The example reads through the data, writing it out to the console window. The code then closes the SqlDataReader. The SqlConnection is closed automatically at the end of the using code block.
Available since 1.1