Data Update Events

When records are updated, the DataTable object raises events that you can respond to as changes are occurring and after changes are made. For more information on Visual Basic events, see Writing Event Handlers. For more information on C# events, see Events Tutorial.

If your application is using a typed dataset, you can create strongly typed event handlers. This will add four additional typed events that you can create handlers for; dataTableNameRowChanging, dataTableNameRowChanged, dataTableNameRowDeleting, and dataTableNameRowDeleted. These typed event handlers pass an argument that includes the column names of your table that make code that easier to write and to read.

The data update events are described in the following table.

EventDescription
ColumnChangingThe value in a column is being changed. The event passes the row and column to you along with the proposed value to be changed to.
ColumnChangedThe value in a column has been changed. The event passes the row and column to you along with the proposed value.
RowChangingChanges made to a DataRow object are about to be committed back into the dataset. If you have not called the BeginEdit method, the RowChanging event is raised for each change to a column, immediately after the ColumnChanging event has been raised. If you did call BeginEdit before making changes, the RowChanging event is raised only when you call the EndEdit method.

The event passes the row to you and a value indicating what type of action (change, insert, and so on) is being performed.

RowChangedA row has been changed. The event passes the row to you and a value indicating what type of action (change, insert, and so on) is being performed.
RowDeletingA row is being deleted. The event passes the row to you and a value indicating what type of action (delete) is being performed.
RowDeletedA row has been deleted. The event passes the row to you and a value indicating what type of action (delete) is being performed.

The ColumnChanging, RowChanging, and RowDeleting events are raised during the update process. You can use these events to validate data or perform other types of processing. Because the updates are in process during these events, you can cancel the update by throwing an exception, which prevents the change from being completed. For more information, see Data Validation in Datasets.

The ColumnChanged, RowChanged, and RowDeleted events are notification events that are raised when the update has been completed successfully. These events are useful when you want to take further action based on a successful update.

See Also

Dataset Updates in Visual Studio .NET | Writing Event Handlers | DataSet Events | DataTable Events | ColumnChanging | RowChanging | RowDeleting | Data Validation in Datasets

Show: