|
-
May 22nd, 2013, 12:00 PM
#1
Thread Starter
Addicted Member
DataGridView does not display the data from XML file
Hi there everyone.
As the titles says, I'm trying to load data into a datagridview from an xml file and the datagridview just doesn't show up any data at all. I've ran the debug to check if the variables and references were working right and it looks to me that the variables are working and recognizing the data on the xml file.
Here's my code:
Code:
Dim yourXmlFileWithFullPath As String = "PortalUNI429.xml"
Dim newDataSet As DataSet = New DataSet("New DataSet")
newDataSet.ReadXml(yourXmlFileWithFullPath)
bsDeliverySites.DataSource = newDataSet
dgDeliverySites.DataSource = bsDeliverySites
dgDeliverySites.DataMember = "Order"
Note: bsDeliverySites is the name of the BindingSource component and dgDeliverySites is the name of the DataGridView component.
I can't post the XML file here, because it's part of the company I'm working at and it has a lot of sensitive information, but I can trully assure everyone that the xml file is 100% correctly coded, as it's being used for a few operations... although I can say that the node after root node is "Order" (this will explain the value of the DataMember field)
Does anyone know what am I missing here?
-
May 22nd, 2013, 12:16 PM
#2
Re: DataGridView does not display the data from XML file
You're filling newDataSet from the xml file and setting the DataGridView's DataSource to bsDeliverySites.
Edit: Missed the not on bsDeliverySites being the BindingSource.
Put a breakpoint after you've filled your DataSet and see if you've got any data in it. Do you have a DataTable called Order in the DataSet?
Last edited by MattP; May 22nd, 2013 at 12:29 PM.
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
May 22nd, 2013, 12:57 PM
#3
Re: DataGridView does not display the data from XML file
bsDeliverySites.DataSource = newDataSet
dgDeliverySites.DataSource = bsDeliverySites
A DGV requires a datatable as its datasource. It cannot handle a DataSet even if there's only one table present. And .... dgDeliverySites.DataMember = "Order" ... doesn't solve that problem either. Also bsDeliverySites is completely redundant. This is all you need ...
dgDeliverySites.DataSource = newDataSet.Tables(0)
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 22nd, 2013, 01:26 PM
#4
Thread Starter
Addicted Member
Re: DataGridView does not display the data from XML file
Thanks for the replies guys, I've found out the problem. I did have everything correct, the problem was that the DGV doesn't show any data on nodes that don't have any text lol.......
Well, this now leads me to a huge head ache... because I need to get blocks of data that I need to edit later on and I need the DGV to show thos blocks of data (i.e. specific tables)...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|