It's very easy to work XML data file with DataSet.
It's just 2 line of code to Read or Write.
Here I have a XML file...
<?xml version="1.0" standalone="yes"?>
<App xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<value>Some Value1</value>
<value>Some Value2</value>
<value>Some Value3</value>
</App>
Here I'm using Visual Studio 2005 and C# language.
now right down this code in some form load event or in button click event.
//variable and dataset name
System.Data.DataSet ds = new System.Data.DataSet("myDataSet");
//file path to read xml
ds.ReadXml(Application.StartupPath + "\\myfile.xml");
//done. Start to read file.
MessageBox.Show(ds.Tables[0].Rows[0][0].ToString());
//here you will show "Some Value1" from xml file.
//Start to write file.
//change some value.
ds.Tables[0].Rows[0][0]="new value.";
//write file.
ds.WriteXml(Application.StartupPath + "\\myfile.xml");
Done.
It's just 2 line of code to Read or Write.
Here I have a XML file...
<?xml version="1.0" standalone="yes"?>
<App xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<value>Some Value1</value>
<value>Some Value2</value>
<value>Some Value3</value>
</App>
Here I'm using Visual Studio 2005 and C# language.
now right down this code in some form load event or in button click event.
//variable and dataset name
System.Data.DataSet ds = new System.Data.DataSet("myDataSet");
//file path to read xml
ds.ReadXml(Application.StartupPath + "\\myfile.xml");
//done. Start to read file.
MessageBox.Show(ds.Tables[0].Rows[0][0].ToString());
//here you will show "Some Value1" from xml file.
//Start to write file.
//change some value.
ds.Tables[0].Rows[0][0]="new value.";
//write file.
ds.WriteXml(Application.StartupPath + "\\myfile.xml");
Done.
0 comments :
Post a Comment