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.

Event Description
ColumnChanging The 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.
ColumnChanged The value in a column has been changed. The event passes the row and column to you along with the proposed value.
RowChanging Changes 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.

RowChanged A 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.
RowDeleting A row is being deleted. The event passes the row to you and a value indicating what type of action (delete) is being performed.
RowDeleted A 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