How to add XML Data to DataGridView using C#
Posted on October 23, 2008
Filed Under Development, Programming | 1 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.
Sphere: Related ContentOther Related Posts:
If you've enjoyed reading this post then why not subscribe to received updates by email.
Email This Post
Trackback This Post
Comments
One Response to “How to add XML Data to DataGridView using C#”
Leave a Reply













I was trying to create this example and ran into a problem with this line of code
ds = DataXml(textBox1.Text);
Where does DataXml come from. did you make this method or is it a built in feature for C#