Victor Charles
asked on
How to delete rows in xml files based on rows selected from a Grid?
Hello,
How do I delete records in my Link.xml file when I delete a record from the grid control. For example if I select a row with Fuze_ID = 5, I would like to loop through my Link.xml file and delete all the records with Fuze_ID = 5.
I'm using the code code below, but I'm receiving the following error:
"Index 5 is either negative or above rows count"
On line: DV.Item(X).Delete()
Any ideas what's wrong with the code.
Thanks,
Victor
Dim dr As DataRow = dt.NewRow()
dr("Link_ID") = linkID
dr("Fuze_ID") = FuzeID
dt.Rows.Add(dr)
Next
'Delete Selecete Record
Dim X As Integer
Dim DV As New DataView(dt, "Fuze_ID like " & "'" & C1TrueDBGrid.Columns(0).Va lue & "'" & "", Nothing, DataViewRowState.CurrentRo ws)
For X = 0 To DV.Count - 1
DV.Item(X).Delete()
Next
Dim DV1 As New DataView(dt, "", Nothing, DataViewRowState.CurrentRo ws)
Dim FilteredDT As DataTable
FilteredDT = DV1.ToTable
'put data back to xml file
FilteredDT.TableName = "Row"
FilteredDT.WriteXml(Applic ation.Star tupPath + "\Link.xml")
How do I delete records in my Link.xml file when I delete a record from the grid control. For example if I select a row with Fuze_ID = 5, I would like to loop through my Link.xml file and delete all the records with Fuze_ID = 5.
I'm using the code code below, but I'm receiving the following error:
"Index 5 is either negative or above rows count"
On line: DV.Item(X).Delete()
Any ideas what's wrong with the code.
Thanks,
Victor
Dim dr As DataRow = dt.NewRow()
dr("Link_ID") = linkID
dr("Fuze_ID") = FuzeID
dt.Rows.Add(dr)
Next
'Delete Selecete Record
Dim X As Integer
Dim DV As New DataView(dt, "Fuze_ID like " & "'" & C1TrueDBGrid.Columns(0).Va
For X = 0 To DV.Count - 1
DV.Item(X).Delete()
Next
Dim DV1 As New DataView(dt, "", Nothing, DataViewRowState.CurrentRo
Dim FilteredDT As DataTable
FilteredDT = DV1.ToTable
'put data back to xml file
FilteredDT.TableName = "Row"
FilteredDT.WriteXml(Applic
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER