_The Problem
I have a dataset/dataview that's getting its data from an XML file (which we're using sort-of like a database). I'm a little more used to contacting SQL servers instead of XML files, but have managed to read from the XML file and read/display the data. I thought I was able to change the data (from a form) as well, but realized the changes to the data were only in the "memory" version of the table and NOT the source document like I want.
This is a problem I ran into when I started using ADO.Net with SQL server, so I know the issue is simply filling in or updating the source file with the changes...I just don't know how to do that in the XML world. So I guess I'm looking for the XML equivalent to "SQLDataAdapter.Fill(DataSet)".
_The Code
Here's a sample of the code as I have it currently:
Expand|Select|Wrap|Line Numbers
- //Initialize dataset/dataview
- DataSet dstMyDataset = new DataSet();
- DataView dvwMyDataview = new DataView();
- //Import XML
- String strFilePath = Application.StartupPath;
- dstMyDataset.ReadXmlSchema(strFilePath + "\\DataDef.xsd");
- dstMyDataset.ReadXml(strFilePath + "\\Data.xml");
- //Example edit of data from form:
- dvwMyDataview[0]["Phone"] = txtPhone.Text;
- //Saving
- dstMyDataview.WriteXml(strFilePath + "\\Data.xml);
As always, I appreciate the help.