XML TO DATAGRIDVIEW IN C#

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
C# 
C#
 1879  View(s)
Ratings:
Rate this:
hi developers,

How to export data XML to DataGridView in C#?

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: XML to DataGridView in C#

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

                }

            }

        }

    }

Answer

NEWSLETTER

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