By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

How to update a DataSet read from XML file ?

rizwan6feb
100+
P: 108
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. Populate my DataSet from the database.
2. Make changes in the DataSet
3. Write the DataSet into XML file using the following statement

Expand|Select|Wrap|Line Numbers
  1. ds.WriteXml("file1.xml", XmlWriteMode.WriteSchema)
4. Read the DataSet from the XML file (after restarting the application) using the following code
Expand|Select|Wrap|Line Numbers
  1. 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 have not added any record to the dataset after populating the dataset from xml file)
Sep 19 '08 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 750
PRR
As far as i can see you are tryin to put duplicate values to database ...as the dataset n xml already has rows that are present in database... got it ?
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. Populate my DataSet from the database. lets say you have 10 rows from databse
2. Make changes in the DataSet // You add 2 more rows so 12
3. Write the DataSet into XML file using the following statement // now 12 rows to XML file

Expand|Select|Wrap|Line Numbers
  1. ds.WriteXml("file1.xml", XmlWriteMode.WriteSchema)
4. Read the DataSet from the XML file (after restarting the application) using the following code // 12 rows read
Expand|Select|Wrap|Line Numbers
  1. 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 have not added any record to the dataset after populating the dataset from xml file)
now thats because you are updating 12 rows... 10 are duplicate
Sep 19 '08 #2

rizwan6feb
100+
P: 108
Yes but how can i make sure that only the records which are added, modified or deleted should be updated in the database
Sep 19 '08 #3

rizwan6feb
100+
P: 108
Still looking for solution
Sep 20 '08 #4

Expert 100+
P: 750
PRR
Still looking for solution
Put the primary keys in a List<String> or any other column that is unique... compare with value in DAtaset .. and if its not there insert into database...
Sep 22 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.