Export (0) Print
Expand All

OracleCommand.ExecuteReader Method (CommandBehavior)

.NET Framework 1.1
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Sends the CommandText to the Connection, and builds an OracleDataReader using one of the CommandBehavior values.

[Visual Basic]
Overloads Public Function ExecuteReader( _
   ByVal behavior As CommandBehavior _
) As OracleDataReader
[C#]
public OracleDataReader ExecuteReader(
 CommandBehavior behavior
);
[C++]
public: OracleDataReader* ExecuteReader(
 CommandBehavior behavior
);
[JScript]
public function ExecuteReader(
   behavior : CommandBehavior
) : OracleDataReader;

Parameters

behavior
One of the System.Data.CommandBehavior values.

Return Value

An OracleDataReader object.

Remarks

If you expect your SQL statement to return only a single row, specifying SingleRow as the CommandBehavior value may improve application performance.

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

The OracleDataReader supports a special mode that enables large binary values to be read efficiently. For more information, see the SequentialAccess setting for CommandBehavior.

More than one OracleDataReader can be open at any given time.

Example

[Visual Basic, C#, C++] The following example creates an OracleCommand, and then executes it by passing a string that is an SQL SELECT statement, and a string to use to connect to the database. CommandBehavior is then set to CloseConnection.

[Visual Basic] 
Public Sub CreateMyOracleDataReader(mySelectQuery As String, _
myConnectionString As String)
    Dim myConnection As New OracleConnection(myConnectionString)
    Dim myCommand As New OracleCommand(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myReader As OracleDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    While myReader.Read()
        Console.WriteLine(myReader.GetString(0))
    End While
    myReader.Close()
    'Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
 End Sub


[C#] 
public void CreateMyOracleDataReader(string mySelectQuery,string myConnectionString) 
{
   OracleConnection myConnection = new OracleConnection(myConnectionString);
   OracleCommand myCommand = new OracleCommand(mySelectQuery, myConnection);
   myConnection.Open();
   OracleDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
   while(myReader.Read()) 
   {
      Console.WriteLine(myReader.GetString(0));
   }
   myReader.Close();
   //Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
}


[C++] 
public:
void CreateMyOracleDataReader(String* mySelectQuery,String* myConnectionString) 
{
   OracleConnection* myConnection = new OracleConnection(myConnectionString);
   OracleCommand* myCommand = new OracleCommand(mySelectQuery, myConnection);
   myConnection->Open();
   OracleDataReader* myReader = myCommand->ExecuteReader(CommandBehavior::CloseConnection);
   while(myReader->Read()) 
   {
      Console::WriteLine(myReader->GetString(0));
   }
   myReader->Close();
   //Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

OracleCommand Class | OracleCommand Members | System.Data.OracleClient Namespace | OracleCommand.ExecuteReader Overload List

Show:
© 2014 Microsoft