How to read data and write data in xml file using C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Data;
namespace XMLform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet vds;
private void button1_Click(object sender, EventArgs e)
{
XmlDataDocument document = new XmlDataDocument();
document.DataSet.ReadXml("C:\\Users\\Cenation\\Documents\\Visual Studio 2010\\Projects\\XMLform\\XMLform\\Lovely.xml");
vds = new DataSet();
vds = document.DataSet;
dataGridView1.DataSource = vds;
dataGridView1.DataMember = "emp";
}
private void button2_Click(object sender, EventArgs e)
{
if (vds.HasChanges())
{
vds.WriteXml("C:\\Users\\Cenation\\Documents\\Visual Studio 2010\\Projects\\XMLform\\XMLform\\Lovely.xml");
MessageBox.Show("Updated Lovely");
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Data;
namespace XMLform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet vds;
private void button1_Click(object sender, EventArgs e)
{
XmlDataDocument document = new XmlDataDocument();
document.DataSet.ReadXml("C:\\Users\\Cenation\\Documents\\Visual Studio 2010\\Projects\\XMLform\\XMLform\\Lovely.xml");
vds = new DataSet();
vds = document.DataSet;
dataGridView1.DataSource = vds;
dataGridView1.DataMember = "emp";
}
private void button2_Click(object sender, EventArgs e)
{
if (vds.HasChanges())
{
vds.WriteXml("C:\\Users\\Cenation\\Documents\\Visual Studio 2010\\Projects\\XMLform\\XMLform\\Lovely.xml");
MessageBox.Show("Updated Lovely");
}
}
}
}
0 comments:
Post a Comment