asp.net.ph

OleDbCommand.ExecuteReader Method ( CommandBehavior )

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;

Parameters

behavior
One of the CommandBehavior values.

Return Value

An OleDbDataReader object.

Exceptions


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.

Remarks

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.

Example

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 ( );
}
  C# VB

See Also

OleDbCommand Members   OleDbCommand.ExecuteReader Overload List Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph