Click here to Skip to main content
15,877,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All, I am using below code to load data from an XML to DataGridView. But Only 3 columns is showing. What need to do differently, to load entire data in XML??

Dim dataSet = New DataSet

        dataSet.ReadXml("C:\Users\Shafiul Alam\Desktop\TEST FILE\TEST FILE\Testing XML Files_V19.Sep\PXSH-QQUBWC_WMB_GMC_11.xml")
        DataGridView1.DataSource = dataSet.Tables(0)

Using XML File as in the link:[^]

Please help..

Share this answer
Shafiul Alam 16-Mar-15 2:58am    
Hi Anand, Thanks for the link. it works. Below is the code. Here I need to specify all the Columns, but in my XML Collection, columns are not fixed. Is there any way I can load all the available columns, without specifying the column names.
Shafiul Alam 16-Mar-15 3:23am    
Dim dt As New DataTable()
dt.Columns.Add("FirstName", GetType(String))
dt.Columns.Add("LastName", GetType(String))
dt.Columns.Add("UserName", GetType(String))
dt.Columns.Add("Role", GetType(String))
Dim xmldoc As New XmlDocument()
xmldoc.Load("C:\Users\Shafiul Alam\Desktop\SampleXML.xml")
Dim nodeList As XmlNodeList = xmldoc.SelectNodes("/users/user")
For Each node As XmlNode In nodeList
Dim dtrow As DataRow = dt.NewRow()
dtrow("FirstName") = node("FirstName").InnerText
dtrow("LastName") = node("LastName").InnerText
dtrow("UserName") = node("UserName").InnerText
dtrow("Role") = node("Job")("Role").InnerText
//Yes you can pls see the following c# code I am not that much aware of VB
//use dataSet and assign load xml file to dataset from there you can bind to your gv as //you did in your QUS that can work..

/// <summary>
/// Bind xml data to datalist
/// </summary>
private void BindDatalist()
XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("Sample.xml"));
DataSet ds = new DataSet();
if (ds.Tables.Count != 0)
dlComments.DataSource = ds;
dlComments.DataSource = null;

Share this answer
Deepu S Nair 16-Mar-15 5:15am    
Instead of adding new solution Use 'Improve soulution link' to update your existing solution.
Shafiul Alam 16-Mar-15 13:09pm    
Hi Anand,

Apology, if I miss something. Its says DataBind is not a property of DataGridView. I was using Below instead. a msg popup after one table loaded and ten next and then next. Please help me to load the entire thing at once.

Dim xmlreader As New XmlTextReader("E:\New folder\Desktop\Desktop\TEST FILE\TEST FILE\Testing XML Files_V19.Sep\4578279_FMRepProdOrder_WMB_GMC20131113 212209.191821.xml")
Dim ds As New DataSet()

For i = 0 To ds.Tables.Count - 1
DataGridView1.DataSource = ds.Tables(i)
MsgBox("Table Loaded")
[no name] 17-Mar-15 5:40am    
Please check it dataset tables count once? xml file contains table and multiple rows & columns.
your code will shows the multiple DVGs if you have more tables in dataset.

As you asked Load data in DataGridView from XML?

try here you can have solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900