Export (0) Print
Expand All

OracleCommand.ExecuteReader Method

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.

Overload List

Sends the CommandText to the Connection and builds an OracleDataReader.

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

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

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

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, C#, C++] Note   This example shows how to use one of the overloaded versions of ExecuteReader. For other examples that might be available, see the individual overload topics.
[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.

See Also

OracleCommand Class | OracleCommand Members | System.Data.OracleClient Namespace

Show:
© 2014 Microsoft