Andrew Truckle
Andrew Truckle

Reputation: 19097

How to save changes back to XML file from a datasource?

Here is the XML file:

<Test>
  <Code Layer='V' Colour='1'/>
  <Code Layer='W' Colour='1'/>
  <Code Layer='WE' Colour='1'/>
</Test>

My Form (WinForm) has a DataGridView on it and I have bound the view to my XML file:

private void GENIO_Code_Editor_Load(object sender, EventArgs e)
{
    DataSet dataSet = new DataSet();
    dataSet.ReadXml("d:\\MyFile.xml");
    dataGridView.DataSource = dataSet.Tables[0];
}

It works (note that example has more codes in the XML file):

Example

My problem is that, if I type in new values at the bottom (asterix row) these new additions are not getting updated in the XML file.

What step am I missing? Thank you.

Upvotes: 1

Views: 276

Answers (1)

dbasnett
dbasnett

Reputation: 11773

The values in the dataset are not saved automatically. To save the dataset use the .WriteXml method.

dataSet.WriteXml("d:\\MyFile.xml");

Upvotes: 1

Related Questions