Question updating the source xml with changes in Datagridview

sinsabit

New member
Joined
Dec 5, 2008
Messages
3
Location
United Kingdom
Programming Experience
Beginner
Hi everyone, it's great to be here for the first time, here's my problem..,

I have the following code to populate a Datagridview from an XML source file:

VB.NET:
  Private Sub FillGrid(ByVal XMLFile As String)
      
        ' Create a new DataSet.
        Dim newDataSet As New DataSet("ds1")

        ' Read the XML document in.
        ' Create new FileStream to read schema with.
        Dim streamRead As New System.IO.FileStream _
           (XMLFile, System.IO.FileMode.Open)

        newDataSet.ReadXml(streamRead)

        Me.DataGridView1.DataSource = newDataSet.Tables(0).DefaultView

        streamRead.Close()

    End Sub
But when the user edits a record in the Datagridview I want to update the XML source file with the changes.

Can anyone give me a clue as the VB.NET coding for that?

Regards

Paul
 
Tried DataSet.WriteXml ?
 
you can store the reference in a class variable:
VB.NET:
Private ds As DataSet

Sub LoadData()
    ds = New DataSet
    ds.ReadXml("file.xml")
    Me.dgv.DataSource = ds.Tables(0)
End Sub

Sub SaveData()
    ds.WriteXml("file.xml")
End Sub
or you can trace the dataset back from the source table of dgv:
VB.NET:
CType(Me.dgv.DataSource, DataTable).DataSet.WriteXml("tempds.xml")
Notice that the DataTable is set as Datasource, it's default DataView is displayed automatically. If you set a different DataView as source you just cast the source to DataView and get the Table property, then the DataSet property.
 
Back
Top