Export (0) Print
Expand All

OracleCommand.Connection Property

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

Gets or sets the OracleConnection used by this instance of the OracleCommand.

[Visual Basic]
Public Property Connection As OracleConnection
[C#]
public OracleConnection Connection {get; set;}
[C++]
public: __property OracleConnection* get_Connection();
public: __property void set_Connection(OracleConnection*);
[JScript]
public function get Connection() : OracleConnection;
public function set Connection(OracleConnection);

Property Value

The connection to a data source. The default is a null value.

Exceptions

Exception Type Condition
InvalidOperationException The Connection property was changed while a transaction was in progress.

Remarks

You cannot set the Connection, CommandType, and CommandText properties if the current connection is performing an execute or fetch operation.

If you set Connection while a transaction is in progress and the Transaction property is not null, an InvalidOperationException is generated. If you set Connection after the transaction has been committed or rolled back, and the Transaction property is not null, the Transaction property is then set to a null value.

Example

[Visual Basic, C#, C++] The following example creates an OracleCommand and sets some of its properties.

[Visual Basic] 
Public Sub CreateMyOracleCommand()
    Dim mySelectQuery As String = _
       "SELECT * FROM Emp ORDER BY EmpNo"
    Dim myCommand As New OracleCommand(mySelectQuery)
    myCommand.Connection = New OracleConnection _
       ("Data Source=Oracle8i;Integrated Security=yes")
    myCommand.CommandType = CommandType.Text
End Sub

[C#] 
public void CreateMyOracleCommand() 
{
   string mySelectQuery = "SELECT * FROM Emp ORDER BY EmpNo";
   OracleCommand myCommand = new OracleCommand(mySelectQuery);
   myCommand.Connection = new OracleConnection
      ("Data Source=Oracle8i;Integrated Security=yes");
   myCommand.CommandType = CommandType.Text;
}

[C++] 
public:
 void CreateMyOracleCommand() 
 {
    String* mySelectQuery = S"SELECT * FROM Emp ORDER BY EmpNo";
    OracleCommand* myCommand = new OracleCommand(mySelectQuery);
    myCommand->Connection = new OracleConnection
       (S"Data Source=Oracle8i;Integrated Security=yes");
    myCommand->CommandType = CommandType::Text;
 }

[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 | CommandText

Show:
© 2014 Microsoft