DataTableReader::HasRows Property

 

Gets a value that indicates whether the DataTableReader contains one or more rows.

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

public:
property bool HasRows {
	virtual bool get() override;
}

Property Value

Type: System::Boolean

true if the DataTableReader contains one or more rows; otherwise false.

Exception Condition
InvalidOperationException

An attempt was made to retrieve information about a closed DataTableReader.

The HasRows property returns information about the current result set. If the DataTableReader contains multiple result sets, you can examine the value of the HasRows property immediately after you call the NextResult method in order to determine whether the new result set contains rows.

Use the HasRows property to avoid the requirement to call the Read method of the DataTableReader if there are no rows within the current result set.

The following example fills two DataTable instances with data. The first DataTable contains one row, and the second contains no rows. The example then creates a DataTableReader that contains both DataTable objects, and calls the PrintData method to display the contents of each, checking the value of the HasRows property of each before it makes the call to PrintData.

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

.NET Framework
Available since 2.0
Return to top
Show: