Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to Detect Changes in a DataTable?
 

How to Detect Changes in a DataTable?

In Asp.Net 2.0, is the a way to detect whether changes have been made to a DataTable without looping thru each row/column?

With a DataSet we can use;

if (ds.HasChanges(DataRowState.Modified))
if (ds.HasChanges(DataRowState.Added))
if (ds.HasChanges(DataRowState.Deleted))

Is there anything similar wth a DataTable?

Thanks
Mike Thomas
M Thomas  Thursday, October 12, 2006 12:30 AM

Remarkably, no. The only built-in way to do this would be to call DataTable.GetChanges(), but since that would copy all of the changed data and could potentially waste a lot of memory, it is probably not a good idea.

The implementation of DataSet.HasChanges() just loops through the tables and rows anyway, so if you implemented your own HasChanges(DataTable) method, that would be the way to do it. Strange that they didn't build that in though, especially with all the upgrades they did to DataTable in 2.0.

CommonGenius.com  Thursday, October 12, 2006 11:42 PM

Remarkably, no. The only built-in way to do this would be to call DataTable.GetChanges(), but since that would copy all of the changed data and could potentially waste a lot of memory, it is probably not a good idea.

The implementation of DataSet.HasChanges() just loops through the tables and rows anyway, so if you implemented your own HasChanges(DataTable) method, that would be the way to do it. Strange that they didn't build that in though, especially with all the upgrades they did to DataTable in 2.0.

CommonGenius.com  Thursday, October 12, 2006 11:42 PM
Many thanks CommonGenius, I figured that must be the case.

Mike Thomas
M Thomas  Friday, October 13, 2006 12:24 PM

You can use google to search for other answers

Custom Search

More Threads

• Databinding LINQ Entity to winform control
• Datagridview - ComboBox column getting blanked out
• Dataview filter on Double data type fails
• Heirarchical data binding
• Needed to reload operating system and have to reload SQL.
• How to obtain a datarow object from the current selected datagrid row?
• adding contents to cell in Datagridview
• DataGridViewColumn with array of RadioButtons
• Edit datagrid cell via combobox
• how to save datagrid information from C# in an ORACLE data base