views:

57

answers:

2

Is there a clean method of creating a DataAdapter SelectCommand to select rows from the database that are not already present in the DataTable? I am calling DataAdapter.Fill(DataTable) and only want to have new rows inserted into the DataTable.

A: 

You can load the complete data into a new datatable and merge it with your old one: http://msdn.microsoft.com/en-us/library/fk68ew7b%28VS.80%29.aspx

I'm afraid thats not a satisfactory answer for you. Whats your use case for it?

Tim Schmelter
A: 

If your data has a datetime (eg. CreaetedOn) field in it, you could use a DataReader implementation that is using a SQL Query to filter on the date and only fill the Table with rows that are newer than the oldest record in your current dataset.

DataAdapter.Fill /w DataReader

You could use this technique also if you have any kind of sequential id, and you would fill with rows whose Id value is larger than the largest value in your in-memory dataset.

Cheers

Dave

Dave White