How to update a DataSet read from XML file ?

rizwan6feb

Member
Joined
Aug 18, 2008
Messages
8
Programming Experience
Beginner
I am working on an application in VB.NET and MySql. I am getting a duplicate entry for key 1 error. My application goes through the following steps.

1. Populates DataSet from the database.
2. Makes changes in the DataSet
3. Writes the DataSet into XML file using the following statement

VB.NET:
Expand Collapse Copy
ds.getChanges().WriteXml("file1.xml", XmlWriteMode.WriteSchema)

4. Read the DataSet from the XML file (after restarting the application) using the following code

VB.NET:
Expand Collapse Copy
ds.ReadXml("file1.xml", XmlReadMode.ReadSchema)

After populating the dataset from XML file, when i update it back in the database, i receive duplicate entry error (even if i only edit existing records)

How can i make sure that only the records which are added, modified or deleted should be updated in the database
 
DataAdapter.Fill(DataSet, TableName)
'Make data changes
DataSet.Tables(TableName).WriteXml(FileName)
 
Sample Code

Hi Tom,
My original code connects to online server my sql server. I have created a similar project ( attached with this message). I have put buttons on the form for every action that my application performs. Please go through the following sequence and you will see duplicate records in the database


1. Connect to Database
2. Save DataSet into XML file
3. Close Application
4. Load DataSet from XML file
5. Update the Database

You will see duplicate records, in the database ( you will find database in the Debug folder)
 

Attachments

Back
Top