IngresDataAdapter Object—Manage Data
An IngresDataAdapter object has four properties for retrieving and updating data source records:
• SelectCommand returns selected data from the data source.
The SelectCommand property must be set before calling the Fill method of the IngresDataAdapter.
• InsertCommand inserts data into the data source.
• UpdateCommand updates data in the data source.
• DeleteCommand deletes data from the data source.
The InsertCommand, UpdateCommand, and DeleteCommand properties must be set before the Update method of the IngresDataAdapter is called, depending on what changes were made to the data in the DataSet. For example, if rows have been added, the InsertCommand must be set before calling Update.
When Update is processing an inserted, updated, or deleted row, the IngresDataAdapter uses the respective Command property to process the action. Current information about the modified row is passed to the Command object through the Parameters collection.
For example, when updating a row, the UPDATE statement uses a unique identifier to identify the row in the table being updated. The unique identifier is commonly the value of a primary key field, or unique non-null index. The UPDATE statement uses parameters that contain the unique identifier, the columns, and the values to be updated, as shown in the following SQL statement:
static void DemoAdapter(string connstring)
{
IngresConnection conn = new IngresConnection (connstring);
IngresDataAdapter adapter = new IngresDataAdapter ();
adapter.SelectCommand = new IngresCommand (
"select * from personnel", conn);
adapter.UpdateCommand = new IngresCommand (
"update personnel set name = ?, number = ? where ssn = ?",
conn);
adapter.UpdateCommand.Parameters.Add(
"@name", IngresType.Char,"name");
adapter.UpdateCommand.Parameters.Add(
"@number", IngresType.Int, "number");
adapter.UpdateCommand.Parameters.Add(
"@oldssn", IngresType.Char, "ssn").SourceVersion =
DataRowVersion.Original;
DataSet ds = new DataSet();
adapter.Fill(ds, "Personnel");
ds.Tables["Personnel"].Rows[195]["number"] = 4199;
adapter.Update(ds, "Personnel");
}