System.Data.OleDb Namespace OleDbCommand Class
Sends the CommandText to the Connection, and builds an OleDbDataReader using one of the CommandBehavior values.
[ VB ]
Overloads Public Function ExecuteReader ( _
ByVal behavior As CommandBehavior _
) As OleDbDataReader
[ C# ]
public OleDbDataReader ExecuteReader (
CommandBehavior behavior
);
[ C++ ]
public: OleDbDataReader* ExecuteReader (
CommandBehavior behavior
);
[ JScript ]
public function ExecuteReader (
behavior : CommandBehavior
) : OleDbDataReader;
- behavior
- One of the CommandBehavior values.
An OleDbDataReader object.
Exception Type |
Condition |
InvalidOperationException |
Occurs when Cannot execute a command within a transaction context that differs from the context in which the connection was originally enlisted. |
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.
When you specify SingleRow for the CommandBehavior, the OLE DB .NET Data Provider performs binding using the OLE DB IRow interface if it is available. Otherwise, it uses the IRowset interface. If your SQL statement is expected to return only a single row, specifying SingleRow can also improve application performance.
The OleDbDataReader supports a special mode that enables large binary values to be read efficiently. For more information, see the SequentialAccess setting for CommandBehavior.
While the OleDbDataReader is in use, the associated OleDbConnection is busy serving the OleDbDataReader. While in this state, no other operatons can be performed on the OleDbConnection other than closing it. This is the case until the Close method of the OleDbDataReader is called.
The following example demonstrates using this version of the ExecuteReader method.
void ExecuteReaderDemo ( string query, string connString ) {
OleDbConnection myConn = new OleDbConnection ( connString );
OleDbCommand myCommand = new OleDbCommand ( query, myConn );
myCommand.Connection.Open ( );
OleDbDataReader myReader =
myCommand.ExecuteReader ( CommandBehavior.CloseConnection );
while ( myReader.Read ( ) ) {
Response.Write ( myReader.GetString ( 0 ) );
}
myReader.Close ( );
myConn.Close ( );
}
Public Sub ExecuteReaderDemo ( query As String, connString As String )
Dim myConn As New OleDbConnection ( connString )
Dim myCommand As New OleDbCommand ( query, myConn )
myCommand.Connection.Open ( )
Dim myReader As OleDbDataReader = _
myCommand.ExecuteReader ( CommandBehavior.CloseConnection )
While myReader.Read ( )
Response.Write ( myReader.GetString ( 0 ) )
End While
myReader.Close ( )
myConn.Close ( )
End Sub |
|
C# |
VB |
OleDbCommand Members OleDbCommand.ExecuteReader Overload List