John Smith
John Smith

Reputation: 4516

what's the proper way to tell if new rows were added to a DataTable after the DataAdapter's Fill() method is called?

I've been playing with the DataTable's RowChanged and RowChanging events, also with the TableNewRow event, and can't get this to work.

essentially what I have is an event handler procedure with code that fills a DataTable and then another event handler procedure with code that refills the same DataTable, and should notify the user that, between calls to the Fill method, new rows were added to the Table (assuming that that is the case).

I've also been playing with the DataRow's indexer and specifying the DataRowVersion and can't get this to work.

I've been playing with the DataAdapter's FillLoadOption method and still can't get this to work.

Can someone give me a hint?

Upvotes: 1

Views: 1368

Answers (1)

Steve
Steve

Reputation: 216333

You could use the DataTable.GetChanges() method to know which rows has been added, modified or deleted from the last AcceptChanges issued against the table

For example:

DataTable added = dt.GetChanges(DataRowState.Added);
int countAdded = added.Rows.Count;

The DataRowState enum gives you the option to select other types of modified rows

Upvotes: 1

Related Questions