Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OleDbDataAdapter & Primary keys

Status
Not open for further replies.

JohnBeton

Programmer
Feb 9, 2004
21
BE
Hi,

I have the following problem when saving data from an XML-file to a database using the OleDbDataAdapter:

I'm using a typed dataset, derived from the xml-schema.
I load the xml-file into the dataset and try to save the data to the database. (the dataAdapter has all the commands (select, insert, update, delete) properly configured.

When it's all new data, there's no problem, all data is saved correctly.

But it's also possible that the xml-file contains data that is already in the database (primary key already exists), so this data needs to be updated (instead of re-inserted)(this is what a dataAdapter takes care of, right ?)

I tried 2 approaches:
1) Only loading the xml-data into the dataset:
When i use the update-method of my dataAdapter and there is data that is already in the database (primary key already exists) i get an oleDbException.

2) First load the database-data in the dataset, and then load the xml-file in the dataset:
I get a ConstraintException while loading the xml-data because primary key already exists in the datatable of the dataset.

How can I fix this problem so that I get 1 table with updated old data and inserted new data ?
Any help is much appreciated... Thanks in advance...
 
Does a Delete work? It almost sounds like maybe your Update SQL is trying to update the PrimaryKey. Good Luck!

Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top