OracleCommand.ExecuteReader Method

Definition

Sends the CommandText to the Connection and builds an OracleDataReader.

Overloads

ExecuteReader()

Sends the CommandText to the Connection and builds an OracleDataReader.

ExecuteReader(CommandBehavior)

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

ExecuteReader()

Sends the CommandText to the Connection and builds an OracleDataReader.

public:
 System::Data::OracleClient::OracleDataReader ^ ExecuteReader();
public System.Data.OracleClient.OracleDataReader ExecuteReader ();
member this.ExecuteReader : unit -> System.Data.OracleClient.OracleDataReader
override this.ExecuteReader : unit -> System.Data.OracleClient.OracleDataReader
Public Function ExecuteReader () As OracleDataReader

Returns

An OracleDataReader object.

Examples

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 data source.

public void CreateMyOracleDataReader(string queryString, string connectionString)
{
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        OracleCommand command = new OracleCommand(queryString, connection);
        connection.Open();
        OracleDataReader reader = command.ExecuteReader();
        try
        {
            while (reader.Read())
            {
                Console.WriteLine(reader.GetValue(0));
            }
        }
        finally
        {
            reader.Close();
        }
    }
}
Public Sub CreateMyOracleDataReader(ByVal queryString As String, _
ByVal connectionString As String)
    Using connection As New OracleConnection(connectionString)
        Dim command As New OracleCommand(queryString, connection)
        connection.Open()
        Dim reader As OracleDataReader = command.ExecuteReader()
        Try
            While reader.Read()
                Console.WriteLine(reader.GetValue(0))
            End While
        Finally
            reader.Close()
        End Try
    End Using
End Sub

Remarks

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.

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

See also

Applies to

ExecuteReader(CommandBehavior)

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

public:
 System::Data::OracleClient::OracleDataReader ^ ExecuteReader(System::Data::CommandBehavior behavior);
public System.Data.OracleClient.OracleDataReader ExecuteReader (System.Data.CommandBehavior behavior);
member this.ExecuteReader : System.Data.CommandBehavior -> System.Data.OracleClient.OracleDataReader
override this.ExecuteReader : System.Data.CommandBehavior -> System.Data.OracleClient.OracleDataReader
Public Function ExecuteReader (behavior As CommandBehavior) As OracleDataReader

Parameters

behavior
CommandBehavior

One of the CommandBehavior values.

Returns

An OracleDataReader object.

Examples

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.

public void CreateMyOracleDataReader(string queryString, string connectionString)
{
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        OracleCommand command = new OracleCommand(queryString, connection);
        connection.Open();

        // Implicitly closes the connection because
        // CommandBehavior.CloseConnection is specified.
        OracleDataReader reader =
            command.ExecuteReader(CommandBehavior.CloseConnection);
        while (reader.Read())
        {
            Console.WriteLine(reader.GetValue(0));
        }
        reader.Close();
    }
}
Public Sub CreateMyOracleDataReader(ByVal queryString As String, _
ByVal connectionString As String)
    Using connection As New OracleConnection(connectionString)
        Dim command As New OracleCommand(queryString, connection)
        connection.Open()

        'Implicitly closes the connection because  
        ' CommandBehavior.CloseConnectionwas specified.
        Dim reader As OracleDataReader = _
            command.ExecuteReader(CommandBehavior.CloseConnection)
        While reader.Read()
            Console.WriteLine(reader.GetValue(0))
        End While
        reader.Close()
    End Using
End Sub

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.

See also

Applies to