OPEN AND READ AN XML FILE TO DATASET

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
C# 
C#
 863  View(s)
Ratings:
Rate this:
Hi MindStickians,

How to Open and read an XML file to Dataset?

Thanks in advance.


  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Open and read an XML file to Dataset

    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());

                }

            }

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!