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.

C#
public System.Data.OracleClient.OracleDataReader ExecuteReader();

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.

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

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

.NET Framework 4.8.1 och andra versioner
Produkt Versioner
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

ExecuteReader(CommandBehavior)

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

C#
public System.Data.OracleClient.OracleDataReader ExecuteReader(System.Data.CommandBehavior behavior);

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.

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

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

.NET Framework 4.8.1 och andra versioner
Produkt Versioner
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1