DB2 Version 10.1 for Linux, UNIX, and Windows

DB2DataAdapter.InsertCommand Property

Gets or sets an SQL statement or stored procedure used to insert new records into the database.

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

Syntax

[Visual Basic]
Public Property InsertCommand As DB2Command

[C#]
public new DB2Command
 InsertCommand {get; set;}
[C++]
public: __property DB2Command
* get_InsertCommand();
public: __property void set_InsertCommand(DB2Command
*);
[JScript]
public function get InsertCommand() : DB2Command
;
public function set InsertCommand(DB2Command
);

Property value

A DB2Command used during an update operation to insert records in the database that correspond to new rows in the DataSet.

Remarks

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

During an update operation, if InsertCommand is not set and primary key information is present in the DataSet, you can use the DB2CommandBuilder class to automatically generate InsertCommand, 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 added to 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 myConnString As String = _
        "DATABASE=SAMPLE;"
     Dim myDataAdapter As New DB2DataAdapter(mySelectText, myConnString)
     Dim myDataAdapter.InsertCommand As New DB2Command(
       "INSERT INTO STAFF 
       VALUES ( 360, 'Johnson',84,'Clerk',2,11500.00, 100.00)", myConnString)
End Sub

[C#]
public void CreateDB2DataAdapter ()
{
    string mySelectText = "SELECT * FROM STAFF ORDER BY ID";
    string myConnString = "DATABASE=SAMPLE;";
    DB2DataAdapter myDataAdapter = new DB2DataAdapter(mySelectText,myConnString);
    myDataAdapter.InsertCommand = new DB2Command(
      "INSERT INTO STAFF 
      VALUES ( 360, 'Johnson',84,'Clerk',2,11500.00, 100.00)", myConnString);
}