Open and read an XML file to Dataset

Total Post:128

Points:898
C# 
C#
 1060  View(s)
Ratings:
Rate this:
Hi MindStickians,

How to Open and read an XML file to Dataset?

Thanks in advance.


  1. 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());
                }
            }
        }
    }

      Modified On Mar-30-2018 04:09:18 AM

Answer

NEWSLETTER

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