Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SqlDataReader::Read Method

Advances the SqlDataReader to the next record.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public:
virtual bool Read() override

Return Value

Type: System::Boolean
true if there are more rows; otherwise false.

Implements

IDataReader::Read()

ExceptionCondition
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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft