Export (0) Print
Expand All

OracleCommand Class

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

Represents an SQL statement or stored procedure to execute against a database. This class cannot be inherited.

For a list of all members of this type, see OracleCommand Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.OracleClient.OracleCommand

[Visual Basic]
NotInheritable Public Class OracleCommand
   Inherits Component
   Implements ICloneable, IDbCommand
[C#]
public sealed class OracleCommand : Component, ICloneable,
   IDbCommand
[C++]
public __gc __sealed class OracleCommand : public Component,
   ICloneable, IDbCommand
[JScript]
public class OracleCommand extends Component implements ICloneable,
   IDbCommand

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The OracleCommand class provides the following methods for executing commands against a data source:

Item Description
ExecuteReader Executes commands that return rows.
ExecuteOracleNonQuery Executes an SQL statement against the Connection and returns the number of rows affected.
ExecuteNonQuery Executes commands such as SQL INSERT, DELETE, UPDATE, and SET statements.
ExecuteScalar Retrieves a single value (for example, an aggregate value) from a database as a .NET Framework data type.
ExecuteOracleScalar Retrieves a single value (for example, an aggregate value) from a database as an Oracle-specific data type.

You can reset the CommandText property and reuse the OracleCommand object.

If execution of the command results in a fatal OracleException, the OracleConnection may close. However, the user can reopen the connection and continue.

Note   Unlike the Command object in the other .NET Framework data providers (SQL Server, OLE DB, and ODBC), OracleCommand does not support a CommandTimeout property. Setting a command timeout has no effect and value returned is always zero.

Example

[Visual Basic, C#, C++] The following example uses the ExecuteReader method of OracleCommand, along with OracleDataReader and OracleConnection, to select rows from a table.

[Visual Basic] 
Public Sub ReadMyData(myConnString As String)
    Dim mySelectQuery As String = "SELECT EmpNo, DeptNo FROM Emp"
    Dim myConnection As New OracleConnection(myConnString)
    Dim myCommand As New OracleCommand(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myReader As OracleDataReader = myCommand.ExecuteReader()
    Try
        While myReader.Read()
            Console.WriteLine(myReader.GetInt32(0) & ", " _
               & myReader.GetInt32(1))
        End While
    Finally
        ' always call Close when done reading.
        myReader.Close()
        ' always call Close when done reading.
        myConnection.Close()
    End Try
End Sub

[C#] 
public void ReadMyData(string myConnString) 
{
   string mySelectQuery = "SELECT EmpNo, DeptNo FROM Emp";
   OracleConnection myConnection = new OracleConnection(myConnString);
   OracleCommand myCommand = new OracleCommand(mySelectQuery,myConnection);
   myConnection.Open();
   OracleDataReader myReader = myCommand.ExecuteReader();
   try 
   {
     while (myReader.Read()) 
    {
       Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetInt32(1));
    }
   }
      finally 
   {
    // always call Close when done reading.
    myReader.Close();
    // always call Close when done reading.
    myConnection.Close();
 }
}

[C++] 
public:
void ReadMyData(String* myConnString) 
{
   String* mySelectQuery = S"SELECT EmpNo, DeptNo FROM Emp";
   OracleConnection* myConnection = new OracleConnection(myConnString);
   OracleCommand* myCommand = new OracleCommand(mySelectQuery,myConnection);
   myConnection->Open();
   OracleDataReader* myReader = myCommand->ExecuteReader();
   try 
   {
     while (myReader->Read()) 
    {
       Console::WriteLine(S"{0}, {1}", __box(myReader->GetInt32(0)), __box(myReader->GetInt32(1)));
    }
   }
   __finally 
   {
    // always call Close when done reading.
    myReader->Close();
    // always call Close when done reading.
    myConnection->Close();
 }
}

[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

Namespace: System.Data.OracleClient

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

Assembly: System.Data.Oracleclient (in System.Data.Oracleclient.dll)

See Also

OracleCommand Members | System.Data.OracleClient Namespace | OracleDataAdapter | OracleConnection

Show:
© 2014 Microsoft