System.Data Namespace IDbCommand Class
Sends the CommandText to the Connection, and builds an IDataReader using one of the CommandBehavior values.
[ VB ]
Overloads Public Function ExecuteReader ( _
ByVal behavior As CommandBehavior _
) As IDataReader
[ C# ]
public IDataReader ExecuteReader (
CommandBehavior behavior
);
[ C++ ]
public: IDataReader* ExecuteReader (
CommandBehavior behavior
);
[ JScript ]
public function ExecuteReader (
behavior : CommandBehavior
) : IDataReader;
- behavior
- One of the CommandBehavior values.
An IDataReader object.
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.
The IDataReader supports a special mode that enables large binary values to be read efficiently. For more information, see the SequentialAccess setting for CommandBehavior.
While the IDataReader is in use, the associated Connection is busy serving the IDataReader. While in this state, no other operatons can be performed on the SqlConnection other than closing it. This is the case until the Close method of the IDataReader is called.
The following examples demonstrate using this version of the ExecuteReader method.
void ExecuteReaderDemo ( string query, string connString ) {
SqlConnection myConn = new SqlConnection ( connString );
SqlCommand myCmd = new SqlCommand ( query, myConn );
myConn.Open ( );
// bind a datalist to the reader
myList.DataSource = myCmd.ExecuteReader ( CommandBehavior.CloseConnection );
myList.DataBind ( );
myConn.Close ( );
}
Public Sub ExecuteReaderDemo ( query As String, connString As String )
Dim myConn As New SqlConnection ( connString )
Dim myCmd As New SqlCommand ( query, myConn )
myConn.Open ( )
' bind a datalist to the reader
myList.DataSource = myCmd.ExecuteReader ( CommandBehavior.CloseConnection )
myList.DataBind ( )
myConn.Close ( )
End Sub |
|
C# |
VB |
IDbCommand Members IDbCommand.ExecuteReader Overload List