views:

25

answers:

3

The DataTable class has RowChanging as well as RowChanged events, which is convenient (for those of us foolish enough to be using the DataTable class in the first place). Event handlers for these events take a parameter of type DataRowChangeEventArgs, whose properties comprise a DataRowAction (Add, Change, Delete, etc.) and the DataRow being changed or having just changed.

Is there any way to actually know which fields of the DataRow are being changed (in the RowChanging event) or have just changed (in the RowChanged event)? If not, is it possible to get this information in some other way?

+1  A: 

for the RowChanging event, if the action is Change you can use the DataRow indexer that takes the DataRowVersion parameter in order to get the old and the new value.
similar approach can be taken for the RowChanged event.

Itay
+1  A: 

If you want to know which fields are changed, I think you're better of using ColumnChanged http://msdn.microsoft.com/en-us/library/system.data.datatable.columnchanged.aspx or ColumnChanging http://msdn.microsoft.com/en-us/library/system.data.datatable.columnchanging.aspx.

In both cases there is an example to get the old and new values.

RonaldV
Man, that is not what I thought it was at all. What a misleading name (in my opinion)! Seems like it should be `FieldChanged` or something like that.
Dan Tao
+1  A: 

Can ColumnChanging Event be of any help?

shahkalpesh