DB2DataAdapter Constructor (DB2Command)
Initializes a new instance of the DB2DataAdapter class with the specified SQL SELECT statement.
- Namespace:
IBM.Data.DB2
- Assembly:
IBM.Data.DB2
(inIBM.Data.DB2.dll
)
Syntax
[Visual Basic]
Public Sub New( _
ByVal selectCommand As DB2Command
_
)
[C#]
public DB2DataAdapter(
DB2Command
selectCommand
);
[C++]
public: DB2DataAdapter(
DB2Command
* selectCommand
);
[JScript]
public function DB2DataAdapter(
selectCommand : DB2Command
);
Parameters
- selectCommand
- A DB2®Command that is an SQL SELECT statement or stored procedure, and is set as the SelectCommand property of the DB2DataAdapter.
Remarks
This implementation of the DB2DataAdapter constructor sets the SelectCommand property to the value specified in the selectCommand parameter.
When you create an instance of DB2DataAdapter, the following read/write properties are set to their default values, as shown in the table.
Properties | Initial value |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
You can change the value of any of these properties through a separate call to the property.
Example
[Visual Basic, C#] The following example creates a DB2DataAdapter and sets some of its properties.
[Visual Basic]
Public Sub CreateDB2DataAdapter()
Dim myDB2Connection As DB2Connection = New DB2Connection("DATABASE=SAMPLE;")
Dim myDB2Command As DB2Command =
New DB2Command("SELECT EMPNO, LASTNAME FROM EMPLOYEE");
Dim custDA As DB2DataAdapter = New DB2DataAdapter(myDB2Command)
custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim custDS As DataSet = New DataSet
custDA.Fill(custDS, "Customers")
custDA.InsertCommand = New DB2Command(
"INSERT INTO EMPLOYEE (EMPNO, LASTNAME) " & _
"VALUES (?, ?)", myDB2Connection)
custDA.UpdateCommand = New DB2Command(
"UPDATE EMPLOYEE SET EMPNO = ?, LASTNAME = ? " & _
"WHERE EMPNO = ?", myDB2Connection)
custDA.DeleteCommand = New DB2Command(
"DELETE FROM EMPLOYEE WHERE EMPNO = ?", myDB2Connection)
custDA.InsertCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO")
custDA.InsertCommand.Parameters.Add("LASTNAME", DB2Type.VarChar, 15, "LASTNAME")
custDA.UpdateCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO")
custDA.UpdateCommand.Parameters.Add("LASTNAME", DB2Type.VarChar, 15, "LASTNAME")
custDA.UpdateCommand.Parameters.Add(
"OLDEMPNO", DB2Type.Char, 6,
"EMPNO").SourceVersion = DataRowVersion.Original
custDA.DeleteCommand.Parameters.Add(
"EMPNO", DB2Type.Char, 6,
"EMPNO").SourceVersion = DataRowVersion.Original
End Sub
[C#]
public static void CreateDB2DataAdapter()
{
DB2Connection myDB2Connection = new DB2Connection("DATABASE=SAMPLE;");
DB2Command myDB2Command =
new DB2Command("SELECT EMPNO, LASTNAME FROM EMPLOYEE");
DB2DataAdapter custDA = new DB2DataAdapter(myDB2Command);
custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataSet custDS = new DataSet();
custDA.Fill(employeeDS, "EMPLOYEE");
custDA.InsertCommand = new DB2Command(
"INSERT INTO EMPLOYEE (EMPNO, LASTNAME) " +
"VALUES (?, ?)", myDB2Connection);
custDA.UpdateCommand = new DB2Command(
"UPDATE EMPLOYEE SET EMPNO = ?, LASTNAME = ? " +
"WHERE EMPNO = ?", myDB2Connection);
custDA.DeleteCommand = new DB2Command(
"DELETE FROM EMPLOYEE WHERE EMPNO = ?",
myDB2Connection);
custDA.InsertCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO");
custDA.InsertCommand.Parameters.Add(
"LASTNAME", DB2Type.VarChar, 15, "LASTNAME");
custDA.UpdateCommand.Parameters.Add("EMPNO", DB2Type.Char, 6, "EMPNO");
custDA.UpdateCommand.Parameters.Add(
"LASTNAME", DB2Type.VarChar, 15, "LASTNAME");
custDA.UpdateCommand.Parameters.Add(
"OLDEMPNO", DB2Type.Char, 6,
"EMPNO").SourceVersion = DataRowVersion.Original;
custDA.DeleteCommand.Parameters.Add(
"EMPNO", DB2Type.Char, 6,
"EMPNO").SourceVersion = DataRowVersion.Original;
}