DB2DataAdapter.UpdateCommand Property

Gets or sets an SQL statement or stored procedure used to update records in the database.

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

Syntax


[Visual Basic]
Public Property UpdateCommand As DB2Command

[C#]
public new DB2Command
 UpdateCommand {get; set;}
[C++]
public: __property DB2Command
* get_UpdateCommand();
public: __property void set_UpdateCommand(DB2Command
*);
[JScript]
public function get UpdateCommand() : DB2Command
;
public function set UpdateCommand(DB2Command
);

Property value

A DB2®Command used during an update operation to update records in the database that correspond to modified rows in the DataSet.

Remarks

When UpdateCommand is assigned to a previously created DB2Command , the DB2Command is not cloned. Instead, the UpdateCommand maintains a reference to the previously created DB2Command object.

During an update operation, if UpdateCommand is not set and primary key information is present in the DataSet, you can use the DB2CommandBuilder class to automatically generate UpdateCommand, and additional commands needed to reconcile the DataSet to the database. To do this, set the SelectCommand property of the DB2DataAdapter . The generation logic also requires key column information to be present in the DataSet. For more information see "Automatically Generated Commands" in the Microsoft(R) .NET Framework SDK documentation.

Note: If execution of this command returns rows, these rows may be merged with the DataSet depending upon how you set the DB2Command.UpdatedRowSource property of the DB2Command object.

Example

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

[Visual Basic]
Public Sub CreateDB2DataAdapter()
     Dim mySelectText As String = _
        "SELECT * FROM STAFF ORDER BY ID"
     Dim myConn As New DB2Connection _
        ("DATABASE=SAMPLE;")
     Dim myDataAdapter As New DB2DataAdapter(mySelectText, myConn)
     Dim myDataAdapter.UpdateCommand As New DB2Command(
       "UPDATE STAFF SET DEPT=100 where JOB='Mgr'", myConnString)
 End Sub

[C#]
public void CreateDB2DataAdapter () {
    string mySelectText = "SELECT * FROM STAFF ORDER BY ID";
    DB2Connection myConn = new DB2Connection("DATABASE=SAMPLE;");
    DB2DataAdapter myDataAdapter = new DB2DataAdapter(mySelectText,myConn);
    myDataAdapter.UpdateCommand = new DB2Command(
      "UPDATE STAFF SET DEPT=100 where JOB='Mgr'", myConnString);
 }