IDbCommand.ExecuteReader Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Executes the CommandText against the Connection and builds an IDataReader.
Overloads
ExecuteReader() |
Executes the CommandText against the Connection and builds an IDataReader. |
ExecuteReader(CommandBehavior) |
Executes the CommandText against the Connection, and builds an IDataReader using one of the CommandBehavior values. |
ExecuteReader()
Executes the CommandText against the Connection and builds an IDataReader.
public:
System::Data::IDataReader ^ ExecuteReader();
public System.Data.IDataReader ExecuteReader ();
abstract member ExecuteReader : unit -> System.Data.IDataReader
Public Function ExecuteReader () As IDataReader
Returns
An IDataReader object.
Applies to
ExecuteReader(CommandBehavior)
Executes the CommandText against the Connection, and builds an IDataReader using one of the CommandBehavior values.
public:
System::Data::IDataReader ^ ExecuteReader(System::Data::CommandBehavior behavior);
public System.Data.IDataReader ExecuteReader (System.Data.CommandBehavior behavior);
abstract member ExecuteReader : System.Data.CommandBehavior -> System.Data.IDataReader
Public Function ExecuteReader (behavior As CommandBehavior) As IDataReader
Parameters
- behavior
- CommandBehavior
One of the CommandBehavior values.
Returns
An IDataReader object.
Remarks
The caller must call the Open method of the Connection property.
When the CommandType property is set to StoredProcedure
, the CommandText property should be set to the name of the stored procedure. The command executes this stored procedure when you call ExecuteReader.
Note
Use SequentialAccess to retrieve large values and binary data. Otherwise, an OutOfMemoryException might occur and the connection will be closed.
While the IDataReader is in use, the associated IDbConnection is busy serving the IDataReader. While in this state, no other operations can be performed on the IDbConnection other than closing it. This is the case until the Close method of the DataReader is called. If the DataReader is created with CommandBehavior set to CloseConnection
, closing the DataReader closes the connection automatically.