Merges an array of System.Data.DataRow objects into the current DataSet, preserving or discarding changes in the DataSet and handling an incompatible schema according to the given arguments.
- rows
- An array of System.Data.DataRow objects to be merged into the current DataSet
- preserveChanges
- true to preserve changes in the target DataSet, false otherwise
- missingSchemaAction
- One of the System.Data.MissingSchemaAction values
Merging is a process of combining two DataSet objects that have similar data schemas. A merge is usually done when an application wants to update its local copy of DataSet with the latest changes from the data source and is typically done after a set of operations that change the state of the data in the data source.
One common scenario is when an application is instructed by a user to submit new data to the data source associated with the current DataSet. In response to the request the application first calls the DataSet.GetChanges method which returns a smaller set of data which contains the changed rows. After retrieving the changes, the application passes the data down to the data source. If necessary (for example if the data source is an RDBMS which uses stored procedures to further process the data), the application can refresh its local copy of the DataSet from the data source by, again, calling GetChanges on the DataSet object bound to the data source.
Merging two DataSet objects may involve combining schemas of the objects as it is possible that the schema in the object being merged in was modified and the changes need to be reflected in the object being merged into. If the DataSet object being merged in contains new columns (that is the System.Data.DataColumn objects were added, the new schema elements can be added to the target DataSet object by calling the DataSet.Merge() method with the missingSchemaAction set to MissingSchemaAction.Add. Merging the schema is always done before merging the data.
During the merge all the rows with the System.Data.DataRowState value of Unchanged, Modified or Deleted are matched against the rows in the target DataSet object with the same primary key. The new rows are copied to the target DataSet object.
During the merge all the constraints in the target DataSet object are disabled. They are re-enabled at the end of the merge and if they fail, a System.Data.ConstraintException exception is raised but the merged in data is left intact in the target DataSet object and the constraints remain disabled. If such situation happens, the DataSet.EnforceConstraints property is set to false and all the rows that failed the constraints are marked as erroneous. It will not be possible to set the DataSet.EnforceConstraints property to true before the errors are resolved.
Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0