DB2DataAdapter Constructor (String, String)

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

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

Syntax


[Visual Basic]
Public Sub New( _
   ByVal selectCommandText As String, _
   ByVal selectConnectionString As String _
)
[C#]
public DB2DataAdapter(
   string selectCommandText,
   string selectConnectionString
);
[C++]
public: DB2DataAdapter(
   String* selectCommandText,
   String* selectConnectionString
);
[JScript]
public function DB2DataAdapter(
   selectCommandText : String,
   selectConnectionString : String
);

Parameters

selectCommandText
A string that is a SQL SELECT statement or stored procedure to be used by the SelectCommand property of the DB2®DataAdapter.
selectConnectionString
The connection string.

Example

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

[Visual Basic]
Public Sub CreateDB2DataAdapter()
    Dim myConnString As String = "DATABASE=SAMPLE;"
    Dim myDB2Connection As DB2Connection = New DB2Connection(myConnString)
    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, "EMPLOYEES")

    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
End Sub

[C#]
public static void CreateDB2DataAdapter()
{

    string myConnString = "DATABASE=SAMPLE;";
    DB2Connection myDB2Connection = new DB2Connection(myConnString);
    string mySelectText = "SELECT EMPNO, LASTNAME FROM EMPLOYEE";
    DB2DataAdapter empDA = new DB2DataAdapter(mySelectText, myDB2Connection);
    empDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;

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

    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;
}