Hi all first post!

I am attempting to read an XML and display certain portions of the XML in a datagridview. I was able to get one table at a time, but I am having trouble figuring out how to get ALL the info I want from the XML and not just one table at a time. I was speaking to someone and they told me that my issue is that the dataset contains datatables and it's not just one big piece of information that I can use. I looked into merge code, but I haven't managed to get anything working the way I would like.
Below is what I have so far:

Imports System.Xml
Imports System.Data
Imports System.Data.OleDb

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xmlFile As XmlReader
        xmlFile = XmlReader.Create("C:\XMLtesting\FVOD_az20100427152451.xml", New XmlReaderSettings())
        Dim ds As New DataSet
        ds.ReadXml(xmlFile)

        DataGridView1.DataSource = (ds.Tables(0, 1))
End Sub
End Class

Edited 6 Years Ago by __avd: Corrected [code] tags.

I'm having issues with the code tag as well it seems. Thought I had it right and it doesnt work no matter what I've tried. LOL.
Now I know I am probably being a complete noob, but I'm new and trying so here goes...

I read through and think I have what's needed, but I am getting the following error from this line in code

ds.Relations.Add(relation)
:
This constraint cannot be enabled as not all values have corresponding parent values.

From the following code:
<code>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xmlFile As XmlReader
xmlFile = XmlReader.Create("C:\XMLtesting\20100427152451.xml", New XmlReaderSettings())
Dim ds As New DataSet
ds.ReadXml(xmlFile)

'creating data relations
Dim relation As DataRelation
Dim table1Column As DataColumn
Dim table2Column As DataColumn
'retrieve column
table1Column = ds.Tables(0).Columns(0)
table2Column = ds.Tables(1).Columns(1)
'relating tables
relation = New DataRelation("relation", table1Column, table2Column)
'assign relation to dataset
ds.Relations.Add(relation)
DataGridView1.DataSource = table1Column

DataGridView2.DataMember = relation.RelationName
DataGridView2.DataSource = table1Column


End Sub

</code>

Edited 6 Years Ago by MaxDes: n/a

This article has been dead for over six months. Start a new discussion instead.