Thursday, 27 June 2013

DataTable Events IN ADO.NET

DataTable Events

DataTable exposes a set of events and  the events can be captured and handled in order to update the user interface, or to validate edits or deletes before they are committed. Not including the event inherited  from MarshalByValueComponent.Disposed, there are nine events in all, and they all work in more-or-less the same way, with similar arguments.


System.Data.DataTable Events

EventDescription
ColumnChangingOccurs when a value is being changed in the specified DataColumn in DataRow.
 ColumnChangedOccurs after a value has been changed in the specified DataColumn in a DataRow.
RowChangingOccurs when a DataRow is changing. This event will fire each time a change is made to the DataRow, after the ColumnChanging event has fired.
RowChangedOccurs after a DataRow has been changed successfully.
TableClearing Occurs when the table is being cleared.
TableClearedOccurs after the table has been cleared.
RowDeleting Occurs when a DataRow is about to be deleted.
TableNew Row Occurs right after a new row has been generated.
RowDeleted Occurs after a DataRow is successfully deleted from the DataTable.


Each of the DataTable events works in the same fashion. Handlers for the column-related events (ColumnChanging and ColumnChanged) receive a DataColumnChangeEventArgs object, which exposes three properties.



DataColumnChangeEventArgs Properties

PropertyDescription
ColumnGet  DataColumn object with the changing value.
Proposed Value
Gets or sets the proposed value—that is, the new value being assigned
to the column. In a ColumnChanging event handler
RowGets the DataRow object with the changing value
The handlers for the row-related events other than the TableNewRow (i.e., RowChanging, RowChanged, RowDeleting, and RowDeleted) take a DataRowChangeEventArgs object, which exposes just two properties


DataRowChangeEventArgs Properties

Property             Description
Action Gets the action (added, changed, deleted, etc.) that will occur/has occurred on the DataRow.
Row  Gets the DataRow object upon which the action will occur/has occurred.

No comments: