Would you like to get paid for signing up for a web hosting plan with Bluehost.com?
Powered by MaxBlogPress 

Would you like to win a Design by Humans t-shirt?
Powered by MaxBlogPress 

How to add XML Data to DataGridView using C#

Posted on October 23, 2008
Filed Under Development, Programming | Leave a Comment

If you've enjoyed reading this post then please subscribe to my Full Text RSS Feed.

This is an example on how to upload the content of a XML file into a DataGridView using Windows Form. First, we create a Windows project in Visual Studio and design the form like the one shown below. Controls to add:

FileUpload control
DataGridView control
Button control


When you run the application and select a XML file using the “Browse” button, the data is taken from the XML file and bound to the DataGridView as shown below.

The Button1_Click event loads the xml content into a DataSet (in this example called ds). Then the Dataset, ds is bound to the DataGridView (dataGridView1).

dataGridView1.DataSource = ds;
dataGridView1.DataMember = “G_EMC_MODEL”;
(”G_EMC_MODEL” is the xml node and all the child node of G_EMC_MODEL is bound to dataGridView1).

The DataXML method as shown below opens the XML file using System.IO.FileStream stream. And the DataSet’s ReadXML method reads the content of the XML file into the DataSet.

That is how simple it is to bind a XML file data to a DataGridView.

Bookmark and Share
Sphere: Related Content

Other Related Posts:

  • Bind data to DropDownList using a DataTable
  • The internet business search engine
  • The end of the road for HD DVD
  • Why use LINQ to SQL?
  • Export GridView Data to MS-Excel

  • If you've enjoyed reading this post then why not subscribe to received updates by email.

    Enter your email address:

    Delivered by FeedBurner

    Email This Post Email This Post

    Trackback This Post

    Comments

    Leave a Reply




    CommentLuv Enabled

    Twitter

    Posting tweet...

    Powered by Twitter Tools