DB2Command Constructor (String, DB2Connection, DB2Transaction)

Initializes a new instance of the DB2Command class with the text of the query, a DB2Connection object, and the Transaction.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax


[Visual Basic]
Public Sub New( _
   ByVal cmdText As String, _
   ByVal connection As DB2Connection , _
   ByVal transaction As DB2Transaction _
)
[C#]
public DB2Command(
   string cmdText,
   DB2Connection connection,
   DB2Transaction transaction
);
[C++]
public: DB2Command(
   String* cmdText,
   DB2Connection* connection,
   DB2Transaction* transaction
);
[JScript]
public function DB2Command(
   cmdText : String,
   connection : DB2Connection,
   transaction : DB2Transaction
);

Parameters

cmdText
The text of the query.
connection
A DB2Connection object that represents an open connection to a data server.
transaction
The transaction in which the DB2Command executes.

Remarks

The following table shows initial property values for an instance of this implementation of the DB2®Command.

Properties Initial value
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection A new DB2Connection that is the value for the connection parameter.

You can change the value for any of these parameters by setting the related property.

Example

[Visual Basic, C#] The following example creates a DB2Command and sets some of its properties.

[Visual Basic]
Public Sub CreateMyDB2Command()
    Dim myConnection As New DB2Connection _
       ("DATABASE=SAMPLE;")
    myConnection.Open()
    Dim myTrans As DB2Transaction = myConnection.BeginTransaction()
    Dim mySelectQuery As String = _
       "SELECT * FROM EMPLOYEE ORDER BY EMPNO"
    Dim myCommand As New DB2Command(mySelectQuery, myConnection, myTrans)
    myCommand.CommandTimeout = 20
End Sub

[C#]
public void CreateMyDB2Command()
{
   DB2Connection myConnection = new DB2Connection("DATABASE=SAMPLE;");
   myConnection.Open();
   DB2Transaction myTrans = myConnection.BeginTransaction();
   string mySelectQuery = "SELECT * FROM EMPLOYEE ORDER BY EMPNO";
   DB2Command myCommand = new DB2Command(mySelectQuery, myConnection,myTrans);
   myCommand.CommandTimeout = 20;
}