connectseekers.com

Friday, 7 August 2015

How To Read XML File In DataSet And Display in DataGridview Using C#.Net

8/07/2015 - By Pranav Singh 0

This article will show you how to read xml file in dataset and display in datagridview c#. In this I have a method to read the xml data and save it into dataset.




Now take a form and add a datagridview control in it.


After this add the below code into the form cs file.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string filepath = @"\XMLDataFile\XMLFile1.xml";
            DataSet objds = new DataSet();
            objds = ReadXMLFile(filepath);
            if (objds.Tables[0].Rows.Count > 0)
            {
                dataGridView1.DataSource = objds.Tables[0];
            }
        }
        /// <summary>
        /// Function to read xml data in datatable
        /// how to read xml file in dataset in c#
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        private DataSet ReadXMLFile(string filePath)
        {
            DataSet objds = new DataSet();
            string fileFinalPath = AppDomain.CurrentDomain.BaseDirectory + filePath;
            objds.ReadXml(fileFinalPath);
            return objds;
        }
    }
}

In above code I have used dataset xml reader to read the file at the given path and store it into dataset object. Now we have done run the application to check the output.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top