XML to DataGridView in C#

Total Post:183

Points:1285
C# 
C#
 2164  View(s)
Ratings:
Rate this:
hi developers,

How to export data XML to DataGridView in C#?

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

      Modified On Mar-30-2018 04:06:19 AM

Answer

NEWSLETTER

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