How to update a DataSet read from XML file ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rizwan6feb
    New Member
    • Jul 2007
    • 108

    How to update a DataSet read from XML file ?

    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

    Code:
    ds.WriteXml("file1.xml", XmlWriteMode.WriteSchema)
    4. Read the DataSet from the XML file (after restarting the application) using the following code
    Code:
    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)
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    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 ?
    Originally posted by rizwan6feb
    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

    Code:
    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
    Code:
    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

    Comment

    • rizwan6feb
      New Member
      • Jul 2007
      • 108

      #3
      Yes but how can i make sure that only the records which are added, modified or deleted should be updated in the database

      Comment

      • rizwan6feb
        New Member
        • Jul 2007
        • 108

        #4
        Still looking for solution

        Comment

        • PRR
          Recognized Expert Contributor
          • Dec 2007
          • 750

          #5
          Originally posted by rizwan6feb
          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...

          Comment

          Working...