Share via


Working with DataSet Events

The DataSet provides a MergeFailed event that will be raised when the schema of the DataSet objects being merged are in conflict. For example, if the primary key columns of a table being merged differ between the tables in the two DataSet objects, an exception will be thrown and the MergeFailed event will be raised. The MergeFailedEventArgs passed to the MergeFailed event have a Conflict property that identifies the conflict in schema between the two DataSet objects, and a Table property that identifies the name of the table in conflict.

For information about other events available when working with a DataSet, see Working with DataTable Events and Working with DataAdapter Events.

The following code example adds the MergeFailed event to an event handler.

Dim custDS As DataSet = New DataSet

AddHandler workDS.MergeFailed, New MergeFailedEventHandler(AddressOf DataSetMergeFailed)

Private Shared Sub DataSetMergeFailed(sender As Object, args As MergeFailedEventArgs)
  Console.WriteLine("Merge failed for table " & args.Table.TableName)
  Console.WriteLine("Conflict = " & args.Conflict)
End Sub
[C#]DataSet custDS = new DataSet();

workDS.MergeFailed += new MergeFailedEventHandler(DataSetMergeFailed);

private static void DataSetMergeFailed(object sender, MergeFailedEventArgs args)
{
  Console.WriteLine("Merge failed for table " + args.Table.TableName);
  Console.WriteLine("Conflict = " + args.Conflict);
}

See Also

Creating and Using DataSets | DataSet Class | MergeFailedEventArgs Class | PropertyChangedEventArgs Class