DB2 Version 10.1 for Linux, UNIX, and Windows

DB2DataAdapter Constructor

Initializes a new instance of the DB2DataAdapter class.

Overload list

Name Description
New()

Initializes a new instance of the DB2®DataAdapter class.

New(DB2Command)

Initializes a new instance of the DB2DataAdapter class with the specified SQL SELECT statement.

New(String, DB2Connection)

Initializes a new instance of the DB2DataAdapter class with an SQL SELECT statement and a DB2Connection .

New(String, String)

Initializes a new instance of the DB2DataAdapter class with an SQL SELECT statement and a connection string.

Example

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

Note: [Visual Basic, C#] This example shows how to use one of the overloaded versions of the DB2DataAdapter constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic]
Public Sub CreateDB2DataAdapter()
    Dim myDB2Connection As DB2Connection = New DB2Connection("DATABASE=SAMPLE;")
    Dim mySelectText as String = "SELECT EMPNO, LASTNAME FROM EMPLOYEE"
    Dim empDA As DB2DataAdapter = New DB2DataAdapter(mySelectText, myDB2Connection)
    empDA.MissingSchemaAction = MissingSchemaAction.AddWithKey

    Dim employeeDS As DataSet = New DataSet()
    empDA.Fill(employeeDS, "EMPLOYEE")

    empDA.InsertCommand = 
      New DB2Command("INSERT INTO EMPLOYEE (EMPNO, LASTNAME) " & _
      "VALUES (?, ?)", myDB2Connection)
    empDA.UpdateCommand = 
      New DB2Command("UPDATE EMPLOYEE SET EMPNO = ?, LASTNAME = ? " & _
      "WHERE EMPNO = ?", myDB2Connection)
    empDA.DeleteCommand = 
      New DB2Command("DELETE FROM EMPLOYEE 
      WHERE EMPNO = ?", myDB2Connection)

    empDA.InsertCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO")
    empDA.InsertCommand.Parameters.Add("LASTNAME", DB2Type.VarChar, 15, "LASTNAME")

    empDA.UpdateCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO")
    empDA.UpdateCommand.Parameters.Add("LASTNAME", DB2Type.VarChar, 15, "LASTNAME")
    empDA.UpdateCommand.Parameters.Add("OLDEMPNO", DB2Type.Char, 6, 
      "EMPNO").SourceVersion = DataRowVersion.Original
    
empDA.DeleteCommand.Parameters.Add("EMPNO", DB2Type.Char, 5, 
  "EMPNO").SourceVersion = DataRowVersion.Original
End Sub
[C#]
public static void CreateDB2DataAdapter()
{
    DB2Connection myDB2Connection = new DB2Connection("DATABASE=SAMPLE;");

    string mySelectText = "SELECT EMPNO, LASTNAME FROM EMPLOYEE";

    DB2DataAdapter empDA = new DB2DataAdapter(mySelectText, myDB2Connection );
    empDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    DataSet employeeDS = new DataSet();
    empDA.Fill(employeeDS, "EMPLOYEE");

    empDA.InsertCommand = new DB2Command("INSERT INTO EMPLOYEE 
      (EMPNO, LASTNAME) " + "VALUES (?, ?)", myDB2Connection);
    empDA.UpdateCommand = new DB2Command("UPDATE EMPLOYEE 
      SET EMPNO = ?, LASTNAME = ? " +
      "WHERE EMPNO = ?", myDB2Connection);
    empDA.DeleteCommand = new DB2Command("DELETE FROM EMPLOYEE 
      WHERE EMPNO = ?", myDB2Connection);

    empDA.InsertCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO");
    empDA.InsertCommand.Parameters.Add("LASTNAME", DB2Type.VarChar, 15, "LASTNAME");

    empDA.UpdateCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO");
    empDA.UpdateCommand.Parameters.Add("LASTNAME", DB2Type.VarChar, 15, "LASTNAME");
    empDA.UpdateCommand.Parameters.Add("OLDEMPNO", DB2Type.Char, 6, 
      "EMPNO").SourceVersion = DataRowVersion.Original;

    empDA.DeleteCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, 
      "EMPNO").SourceVersion = DataRowVersion.Original;
}