Home > DeveloperSection > Forums > XML to DataGridView in C#
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    June-15-2013 5:21 AM

 C# C# 
Ratings:


 1 Reply(s)
 1526  View(s)
Rate this:
hi developers,

How to export data XML to DataGridView in C#?



Sumit Kesarwani

Total Post:378

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

Hi Ankita,

The following code will solve your problem:

using System;

using System.Data;

using System.Windows.Forms;

using System.Xml;

using System.Data;

 

namespace WindowsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            try

            {

                XmlReader xmlFile;

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

                DataSet ds = new DataSet();

                ds.ReadXml(xmlFile);

                dataGridView1.DataSource = ds.Tables[0];

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }

        }

    }

}


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

Follow MindStick