Merges this DataSet into a specified DataSet.
[Visual Basic] Overloads Public Sub Merge( _ ByVal dataSet As DataSet _ ) [C#] public void Merge( DataSet dataSet ); [C++] public: void Merge( DataSet* dataSet ); [JScript] public function Merge( dataSet : DataSet );
Exception Type | Condition |
---|---|
InvalidConstraintException | One or more constraints cannot be enabled. |
ArgumentNullException | The dataSet is a null reference (in Visual Basic Nothing). |
The Merge method is typically called after invoking the GetChanges method, which returns a DataSet optimized for merging.
To facilitate explanation of the Merge method, we use "target" to signify the current DataSet, and "source" to name the second (parameter) DataSet.
When the Merge method is called, the schemas of the two DataSet objects are compared. If the source DataSet contains schema elements that are missing in the target, the schema elements are added to the target. The data is then merged. When merging rows that have a DataRowState value of Unchanged, Modified, or Deleted source rows, the source's primary key is used to search for target rows that have the same primary key values. When merging New source rows, the new primary key value is used to search for target rows that are also New and have matching new primary keys.
If the source DataSet originated from a call to GetChanges on the target DataSet, a different matching procedure is employed. The source DataSet rows are matched up with the target rows they were cloned from. Once a match is found, original values in the target rows are updated with values from the source rows, while the changed values remain the same.
During a merge, constraints are disabled. If any constraints can't be enabled at the end of merge, an InvalidConstraintException is thrown and the data is kept with the constraints disabled.
DataSet Class | DataSet Members | System.Data Namespace | DataSet.Merge Overload List | ForeignKeyConstraint | UniqueConstraint