IfxCommandBuilder object to reconcile changes with the database
You can use the IfxCommandBuilder object to retrieve data with an SQL SELECT statement, make changes in the data set, and then reconcile those changes with the HCL OneDB™ database.
The IfxCommandBuilder object facilitates easy reconciliation of changes made in your data set with the database.
For more information about the IfxCommandBuilder class, see IfxCommandBuilder class. For more information about reconciling changes in the database, see Reconcile DataSet changes with the database.
The following example shows how to use the IfxCommandBuilder object.
// Add the IBM Informix namespace
using System.Data;
using Informix.Net.Core;
// Create a connection
IfxConnection conn=new IfxConnection("Host=berry; Service=3500;
Server=testserver; User ID=informix; password=ifxtest;
Database=testdb");
// Create a DataAdapter object
IfxDataAdapter allDataAdapter = new IfxDataAdapter();
IfxCommand selCmd = new IfxCommand("SELECT * FROM students", conn);
allDataAdapter.SelectCommand = selCmd;
//Set up the CommandBuilder object
IfxCommandBuilder cbuild = new IfxCommandBuilder(allDataAdapter);
DataSet allDataSet = new DataSet ();
try
{
// Open the connection
conn.Open();
allDataAdapter.Fill(allDataSet);
// Change the age of a student
DataRow chRow;
chRow = allDataSet.Tables["Table"].Rows[5];
chRow["age"] = 24;
// Use IfxDataAdapter.Update() to reconcile changes with the database
allDataAdapter.Update(allDataSet);
}
catch (Exception ex)
{
// Use a messagebox to show any errors
MessageBox.Show (ex.Message);
}
// Close the connection
conn.Close();