Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

XML duplicates records when passed from another form

$
0
0

Hello,

I have written a program to update an XML file with specific values. I have run the program and confirmed that it work successfully except for in one case.

The XML file is loaded into a dataset and the first 2 tables are loaded into the main form (this information contains "header information"). The user then presses a button and another form opens from which the user can display the part information to confirm the new data is correct before updating. 

For testing purposes, I added a textbox with a string ("TEXTBOX1") onto the second form. During the second form's closing event, the data from the textbox is passed to the dataset. The user then hits the update button on the main form and the XML is updated and saved with a new file name. I have tested this multiple times and confirmed that it works however, duplicate records appear in the XML file.

The original XML file would look something like this:

<root>
  <PartInformation>
     <PartName>Hex Bolt</PartName>
     <DetailedInfo>
       <PartNumber>88-901</PartNumber>
       <SerialNumber>SN1234</SerialNumber>
     </DetailedInfo>
  </PartInformation>
etc...
</root>

After the update the new XML file would look like this:

<root>
  <PartInformation>
     <PartName>TEXTBOX1</PartName>
     <PartNumber>88-901</PartNumber>
     <SerialNumber>SN1234</SerialNumber>
     <DetailedInfo>
       <PartNumber>88-901</PartNumber>
       <SerialNumber>SN1234</SerialNumber>
     </DetailedInfo>
  </PartInformation>
etc...
</root>

While the updated value appears correctly I'm not sure why the data repeats itself. I've pinpointed the source of the problem (I think, to the following code in my second form):

Private Sub LoadInfo(sender As Object, e As EventArgs) Handles LoadData.Click
        Dim comboPartTable As New DataTable
        Dim tableFilter As String = Nothing
        tableFilter = "SlotFindNumber LIKE 'FIND503%'"
        comboPartTable = Form1.ds.Tables(4)
        comboPartTable.Merge(Form1.ds.Tables(5))
        DataGridView1.DataSource = comboPartTable.Select(tableFilter).CopyToDataTable
        DataGridView1.Columns.Remove("SubAssembly_Id")
        DataGridView1.Columns.Remove("Data_Id")
    End Sub
As mentioned above, the only purpose of this code is to display the old values of the data so the user can see the

previous data. If I comment this Sub out and run the program, the second form can be opened, closed and the 1 piece of data updated in the XML without any records repeating themselves.

To help anyone looking at the code block, I merged 2 tables from the dataset that contain all the part information and then used the filter to only display the records that are being updated.

Any help would be appreciated as I can't figure out why this occurs.
Thanks to anyone who looks at this!!!


Join the darskide. We have cookies!


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>