XML file corrupt after deleting a record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emphyrio
    New Member
    • Feb 2008
    • 3

    XML file corrupt after deleting a record

    Hi, I am new to programming in vb. net. I have this problem:

    I created a form with a datagrid. I can add records and then save them to a XML file, using this code on the click event of a button (my dataset is called Maxdata1):

    Dim fs As Stream
    Me.BindingConte xt(Maxdata1, "addresses").En dCurrentEdit()
    fs = New FileStream("D:\ temp\maxdata.xm l", FileMode.OpenOr Create)
    Maxdata1.WriteX ml(fs)
    fs.Close()

    This works fine, and I can retrieve the data from the xml file as well. Now here is the problem: when I delete a record in the grid and then save the data to the XML file, the file is corrupted and does not have the nodes of the data anymore.

    Is there a special action I have to take after deleting a record, before I save the data to the file?

    Thx,
    emphyrio
  • emphyrio
    New Member
    • Feb 2008
    • 3

    #2
    Additional information: I examined the XML file after the delete and this is what happens:

    <maxdata xmlns="http://tempuri.org/maxdata.xsd">
    <addresses street="serpeli ng" housenumber="10 " />
    <addresses street="markstr aat" housenumber="12 7" />
    </maxdata>es street="kerkstr aat" housenumber="4" />
    </maxdata>


    The part in bold should not be there, tha is the data that was deleted in the grid control... Somehow the writeXML does not truncate the remainder of the deleted record. How can I solve this problem?

    Comment

    • emphyrio
      New Member
      • Feb 2008
      • 3

      #3
      I solved the problem: by not using a filestream, but writing directly to the file! It's strange that is goes wrong whern using the filestream, but I'm glad I solved it though...

      Comment

      Working...