Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent duplicates in XML file

Status
Not open for further replies.

ComputersUnlimited

IS-IT--Management
Dec 18, 2013
37
US
The program I am working on has four combo boxes in a control array. They all contain the same items which are to be saved to an XML file which may also have some of the same values as the combo boxes. I want to prevent duplicates being saved to the XML file. What is the best way to accomplish this. I have tried a couple of things but keep failing.

I have tried loops with a lot of lines of code and if statements which didn't prevent duplicates. I also tried lists but got conversation exceptions.

Thank You
 
1) Load the XML file into a DataTable (2) Set the RowFilter property of the DefaultView property of the DataTable, using the fields/values of the ComboBoxes (3) If the RowFilter returns row(s), then the data are already in the XML file. (If DataTable.DefaultView.Count > 0 Then....)

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you for the reply.

I apologize I forgot to clarify that I am using xelement to read and write to the XML.
 
I'm not all that familiar with Linq, but I think you can filter the xelement with the combobox values and if there are any elements returned then the data are already in the file.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
ComputersUnlimited said:
four combo boxes [...] contain the same items which are to be saved to an XML file which may also have some of the same values as the combo boxes

Looks to me you may just limit what data is displayed in your 4 combo boxes.
Every combo box would have a full list of Items - excluding the items already in the XML file and excluding the items in other 3 combo boxes.



---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top