System.Data.IDataAdapter.Update Method

Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified System.Data.DataSet from a System.Data.DataTable named "Table".

Syntax

public int Update (DataSet dataSet)

Parameters

dataSet
The System.Data.DataSet used to update the data source.

Returns

The number of rows successfully updated from the System.Data.DataSet.

Remarks

When an application calls the IDataAdapter.Update(DataSet) method, the System.Data.IDataAdapter examines the DataRow.RowState property, and executes the required INSERT, UPDATE, or DELETE statements iteratively for each row, based on the order of the indexes configured in the System.Data.DataSet. For example, IDataAdapter.Update(DataSet) might execute a DELETE statement, followed by an INSERT statement, and then another DELETE statement, because of the ordering of the rows in the System.Data.DataTable.

Be aware that these statements are not performed as a batch process; each row is updated individually. An application can call the DataSet.GetChanges method if you must control the sequence of statement types (for example, INSERTs before UPDATEs). For more information, see [<topic://cpconUpdatingDatabaseWithDataAdapterDataSet>].

If INSERT, UPDATE, or DELETE statements have not been specified, the System.Data.Common.DataAdapter.Update(DataSet) method generates an exception. However, you can create a System.Data.SqlClient.SqlCommandBuilder or System.Data.OleDb.OleDbCommandBuilder object to automatically generate SQL statements for single-table updates if you set the SelectCommand property of a .NET Framework data provider. Then, any additional SQL statements that you do not set are generated by the CommandBuilder. This generation logic requires key column information to be present in the System.Data.DataSet. For more information see [<topic://cpconAutomaticallyGeneratedCommands>].

The System.Data.Common.DataAdapter.Update(DataSet) method retrieves rows from the table listed in the first mapping before performing an update. The System.Data.Common.DataAdapter.Update(DataSet) then updates the row using the value of the IDbCommand.UpdatedRowSource property. Any additional rows returned are ignored.

After any data is loaded back into the System.Data.DataSet, the System.Data.Common.DbDataAdapter.OnRowUpdated(System.Data.Common.RowUpdatedEventArgs) event is raised, allowing the user to inspect the reconciled System.Data.DataSet row and any output parameters returned by the command. After a row updates successfully, the changes to that row are accepted.

When using IDataAdapter.Update(DataSet), the order of execution is as follows:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

Each command associated with the System.Data.IDataAdapter usually has a parameter collection associated with it. Parameters are mapped to the current row through the SourceColumn and SourceVersion properties of a .NET Framework data provider's Parameter class. SourceColumn refers to a System.Data.DataTable column that the System.Data.IDataAdapter references to obtain parameter values for the current row.

SourceColumn refers to the unmapped column name before any table mappings have been applied. If SourceColumn refers to a nonexistent column, the action taken depends on one of the following System.Data.MissingMappingAction values.

MissingMappingAction.Passthrough

Use the source column names and table names in the System.Data.DataSet if no mapping is present.

MissingMappingAction.Ignore

A SystemException is generated. When the mappings are explicitly set, a missing mapping for an input parameter is usually caused by an error.

MissingMappingAction.Error

A SystemException is generated.

The SourceColumn property is also used to map the value for output or input/output parameters back to the DataSet. An exception is generated if it refers to a nonexistent column.

The SourceVersion property of a .NET Framework data provider's Parameter class determines whether to use the Original, Current, or Proposed version of the column value. This capability is frequently used to include original values in the WHERE clause of an UPDATE statement to check for optimistic concurrency violations.

Note:

If an error occurs while updating a row, an exception is thrown and execution of the update is discontinued. To continue the update operation without generating exceptions when an error is encountered, set the System.Data.Common.DataAdapter.ContinueUpdateOnError property to true before calling System.Data.Common.DbDataAdapter.Update(DataSet). You may also respond to errors on a per-row basis within the RowUpdated event of a DataAdapter. To continue the update operation without generating an exception within the RowUpdated event, set the System.Data.Common.RowUpdatedEventArgs.Status property of the System.Data.Common.RowUpdatedEventArgs to UpdateStatus.Continue.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0