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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete row from dataset and write to xml 1

Status
Not open for further replies.

SMURF75

Programmer
Aug 28, 2004
87
GB
Hi!

Im running out of ideas here. Im trying to delete a row from my dataset which is retrived from an xml file. I can add rows fine, but when I try to delete a row I get a lot of "mumbojumbo". The xml file gets really messed up with elements in disorder and duplicate rows.

my current code looks like

Code:
Dim DS As DataSet
Dim DR As DataRow

DS = oXmlHandlerCF.getDataSet

                For Each DR In DS.Tables("User").Rows

                    If DR.Item("UserId").ToString Like _ lvUsers.FocusedItem.Text Then
                        DS.Tables("User").Rows.Remove(DR)
                        DR.Delete()
                        DS.AcceptChanges()
                        Exit For
                    End If
                Next

oXmlHandlerCF.saveDataSet(DS)

the code is for compact.net which lacks support of typed datasets, but i dont know if my problems depends on that since I as I already said can add rows without problems.

- - - - - - - - - - - - - - - - - -
Im three apples high, Im blue, and i most certainly like that cold beer that should be every mans right after a hard days work!
 
Well, it's be a bit of extra work, but you could read the data in, delete the xml file, delete the row, then write the dataset to XML again. You're probrably have to split it up in 2 different datasets though.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Problem solved. The error wasnt in the code i posted. I didnt really use your solution, but it sure was you who lead me on the way Rick. Instead of trying to add the data to the old xmlfile I simply created a new. I got all the data I need in the dataset so it was just to replace FileMode.OpenCreate With FileMode.Create in my filestream.

Lucky for me ive havnt had time to use your xmlwrite solution without filestream from yesterday... :)

A star you are....

- - - - - - - - - - - - - - - - - -
Im three apples high, Im blue, and i most certainly like that cold beer that should be every mans right after a hard days work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top