System.Data.SqlClient.SqlCommand.ExecuteReader Method

Sends the SqlCommand.CommandText to the SqlCommand.Connection and builds a System.Data.SqlClient.SqlDataReader.

Syntax

public SqlDataReader ExecuteReader ()

Returns

A System.Data.SqlClient.SqlDataReader object.

Remarks

When the SqlCommand.CommandType property is set to StoredProcedure, the SqlCommand.CommandText property should be set to the name of the stored procedure. The command executes this stored procedure when you call SqlCommand.ExecuteReader.

Note:

If a transaction is deadlocked, an exception may not be thrown until SqlDataReader.Read is called.

The multiple active result set (MARS) feature allows for multiple actions using the same connection.

If you use SqlCommand.ExecuteReader or SqlCommand.BeginExecuteReader to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use SqlCommand.ExecuteXmlReader or erload:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader to read FOR XML queries. For more information, see article Q310378, "PRB: XML Data Is Truncated When You Use SqlDataReader," in the Microsoft Knowledge Base at http://support.microsoft.com.

Requirements

Namespace: System.Data.SqlClient
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0