Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

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?

0
IvanHowarth
Asked:
IvanHowarth
  • 2
2 Solutions
 
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 vb.net, but know that this is the way to go, hope it helps already
0
 
hatem72Commented:
0
 
hatem72Commented:

i am happy that i could help
0
 
IvanHowarthAuthor Commented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now