Read Method

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.

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.

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

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft