DB2DataAdapter Constructor (String, DB2Connection)
Initializes a new instance of the DB2DataAdapter class with an SQL SELECT statement and a DB2Connection.
- Namespace:
IBM.Data.DB2
- Assembly:
IBM.Data.DB2
(inIBM.Data.DB2.dll
)
Syntax
[Visual Basic]
Public Sub New( _
ByVal selectCommandText As String, _
ByVal selectConnection As DB2Connection _
)
[C#]
public DB2DataAdapter(
string selectCommandText,
DB2Connection
selectConnection
);
[C++]
public: DB2DataAdapter(
String* selectCommandText,
DB2Connection* selectConnection
);
[JScript]
public function DB2DataAdapter(
selectCommandText : String,
selectConnection : DB2Connection
);
Parameters
- selectCommandText
- A string that is a SQL SELECT statement or stored procedure to be used by the SelectCommand property of the DB2®DataAdapter.
- selectConnection
- A DB2Connection object that represents an open connection to a database.
Remarks
This implementation of the DB2DataAdapter can be useful in an application that must call the Fill method for two or more DB2DataAdapter objects.
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 mySelectText As String = "SELECT EMPNO, LASTNAME FROM EMPLOYEE"
Dim custDA As DB2DataAdapter = New DB2DataAdapter(mySelectText, myDB2Connection)
custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim custDS As DataSet = 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
End Sub
[C#]
public static void CreateDB2DataAdapter()
{
DB2Connection myDB2Connection = new DB2Connection("DATABASE=SAMPLE;");
string mySelectText = "SELECT CustomerID, CompanyName FROM CUSTOMERS";
DB2DataAdapter custDA = new DB2DataAdapter(mySelectText, myDB2Connection );
custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "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;
}