Home > DeveloperSection > Forums > Open and read an XML file to Dataset
Ashish Pandey

Total Post:128

Points:898
Posted on    June-15-2013 5:11 AM

 C# C# 
Ratings:


 1 Reply(s)
 635  View(s)
Rate this:
Hi MindStickians,

How to Open and read an XML file to Dataset?

Thanks in advance.




Sumit Kesarwani

Total Post:378

Points:2694
Posted on    June-15-2013 7:28 AM

Hi Ashish, 

The following code will solve your problem:

using System;

using System.Data;

using System.Windows.Forms;

using System.Xml;

 

namespace WindowsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            XmlReader xmlFile;

            xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());

            DataSet ds = new DataSet();

            ds.ReadXml(xmlFile);

            int i = 0;

            for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)

            {

                MessageBox.Show(ds.Tables[0].Rows[i].ItemArray[2].ToString());

            }

        }

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick