Automatically generates single-table commands used to reconcile changes made to a
System.Data.DataSet with the DB2.
The following example uses
DB2Command, along with
DB2DataAdapter and
DB2Connection, to select rows from DB2. The example is passed an initialized
System.Data.DataSet, a connection string, a query string that is SQL SELECT statement, and a string that is the name of the DB2 table. The example then creates a
DB2CommandBuilder.
|
|---|
public DataSet SelectDB2SrvRows(DataSet myDataSet,string db2Connection,string mySelectQuery,string myTableName)
{
DB2Connection myConn = new DB2Connection(db2Connection);
DB2DataAdapter myDataAdapter = new DB2DataAdapter();
myDataAdapter.SelectCommand = new DB2Command(mySelectQuery, myConn);
DB2CommandBuilder db2CommandBuilder = new DB2CommandBuilder(myDataAdapter);
myConn.Open();
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "Departments");
//code to modify data in dataset here
//Without the DB2CommandBuilder this line would fail
myDataAdapter.Update(myDataSet, "Departments");
myConn.Close();
return myDataSet;
} |
|
|---|
Public Function SelectDB2SrvRows(myDataSet As DataSet, db2Connection As String, mySelectQuery As String, myTableName As String) As DataSet
Dim myConn As New DB2Connection(db2Connection)
Dim myDataAdapter As New DB2DataAdapter()
myDataAdapter.SelectCommand = New DB2Command(mySelectQuery, myConn)
Dim db2CommandBuilder As DB2CommandBuilder = New DB2CommandBuilder(myDataAdapter)
myConn.Open()
Dim myDataSet As DataSet = New DataSet
myDataAdapter.Fill(myDataSet, "Departments")
' Code to modify data in DataSet here
' Without the DB2CommandBuilder this line would fail.
myDataAdapter.Update(myDataSet, "Departments")
myConn.Close()
SelectDB2SrvRows = myDataSet
End Function |