How do I explicitly get my DataAdapter to insert an edited record as a new one instead of updating it?

The Background:

I have a form full of controls bound to a DataTable. This DataTable is one of two in the DataSet, each filled
by their respective DataAdapters and the data source amended accordingly by the DataAdapters Insert/Update/Delete

The Scenario:

I want to build up my data base using my form, but in most cases each record I want to add is slightly different to the last. Instead of re-entering all the data into each control, I want to fill my form with a record (select command), make a slight change and then save it as a new record (insert command).

The Problem:

The myDataAdapter.Update(MyDataSet.MyDataTable1) will overwrite my original record. How do I explicitly insert the amended record as a new record in the data source?

Who is Participating?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Simply assign a SqlCommand that does a INSERT instead of a UPDATE to the dataadapters' UpdateCommand property.
By default, the dataadapter generates a Update command automatically, which you can however override.
I am not really good yet in, but know that this is the way to go, hope it helps already

i am happy that i could help
IvanHowarthAuthor Commented:

Your approach is a simple (and cheeky) concept that worked. The only thing that caught me out was one of my two tables I applied this concept to had all the datarows set with the old (so wrong) PK value. A quick loop in changing it to the new value then gave me a new record in the source table.


Unfortuantely I was nearly there with the above when I saw your more official approach. It nevertheless, I'm sure, would have got me to the same result.

Thanks both anyway.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.