Link to home
Start Free TrialLog in
Avatar of IvanHowarth
IvanHowarth

asked on

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
sqlCommands.

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?

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hatem72
hatem72


i am happy that i could help
Avatar of IvanHowarth

ASKER

angelIII

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.

hatem72

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.