Using a datatable to update rows and not insert when the row did not originate in the datatable with acceptchanges() and setmodified() One of my recent applications had an issue which is probably very common.
I was fetching data out of a database and putting it into a datatable, and then converting the datatable to a collection of business objects.
For example, if you call Delete on a row on the Data Set, then when Update is called on the Data Adapter, the Delete Command of the Data Adapter will be called using the particular row in the Data Set.
Note: Keep in mind that this Update is different than a SQL UPDATE statement.
I finally came across this solution, which is quite elegant and very easy to implement. You cannot call Set Modified without calling Accept Changes, as the setmodified function only works on rows that are set as unmodified.
Hopefully the entire ORM problem is solved in the future by things like LINQ, but until then, this is a nice workaround.
So Let’s start with post with a very often situation in our coding life.
The Add New method of the Data Table adds a row to a Data Table.Now we use this Data Set as a Data Source of any of the Data Control like; Grid View, List View etc for showing this Data to User.