Working with DataSet Events
Theobject provides three events: , and .
The MergeFailed Event
The most commonly used event of the DataSet object is MergeFailed, which is raised when the schema of the DataSet objects being merged are in conflict. This occurs when a target and sourcehave the same primary key value, and the property is set to true. For example, if the primary key columns of a table being merged differ between the tables in the two DataSet objects, an exception is thrown and the MergeFailed event is raised. The passed to the MergeFailed event have a property that identifies the conflict in schema between the two DataSet objects, and a property that identifies the name of the table in conflict.
The following code fragment demonstrates how to add an event handler for the MergeFailed event.
The Initialized Event
Theevent occurs after the DataSet constructor initializes a new instance of the DataSet.
Themethod returns true if the DataSet has completed initialization; otherwise it returns false. The method, which begins the initialization of a DataSet, sets it to false. The method, which ends the initialization of the DataSet, sets it to true. These methods are used by the Visual Studio .NET design environment to initialize a DataSet that is being used by another component. You will not commonly use them in your code.
The Disposed Event
DataSet is derived from theclass, which exposes both the method and the Disposed event. The Disposed event adds an event handler to listen to the disposed event on the component. You can use the Disposed event of a DataSet if you want to execute code when the Dispose method is called. Dispose releases the resources used by the MarshalByValueComponent.
The DataSet and DataTable objects inherit from MarshalByValueComponent and support theinterface for remoting. These are the only ADO.NET objects that can be remoted. For more information, see .
For information about other events available when working with a DataSet, seeand .