emi_sastra
asked on
READ MULTIPLE TABLES OF XML FILE TO DATASET
Hi All,
I have a xml file. It could be opened using browser, but I can not read it to dataset.
Please see my code below.
What's wrong ?
Thank you.
I have a xml file. It could be opened using browser, but I can not read it to dataset.
Please see my code below.
What's wrong ?
Thank you.
Dim dsTables As DataSet = Nothing
Dim xmlFile As XmlReader
Try
Dim strSourceFromClientFolder As String = System.AppDomain.CurrentDomain.BaseDirectory()
Dim strXMLFileName As String = strSourceFromClientFolder & "121110110334.xml"
xmlFile = XmlReader.Create(strXMLFileName, New XmlReaderSettings())
dsTables.ReadXml(xmlFile)
dgvTables.DataSource = dsTables
Catch ex As Exception
MsgBox("Gagal Buka XML File ...!", MsgBoxStyle.Information, Me.Text)
End Try
121110110334.xml
ASKER
Very weird.
I've got exception "object reference not set to an instance of object" at :
dsTables.ReadXml(strXMLFil eName)
Why is that ?
Thank you.
I've got exception "object reference not set to an instance of object" at :
dsTables.ReadXml(strXMLFil
Why is that ?
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, it works.
Would you please help how to fill it to fill to datagridview ?
For Each dtTable As DataTable In dsTables.Tables
Dim dgvRow As New DataGridViewRow
Dim dgvCell As DataGridViewCell
dgvCell = New DataGridViewTextBoxCell()
-------> dgvCell.Value = dtTable.n
dgvRow.Cells.Add(dgvCell)
dgvTables.Rows.Add(dgvRow)
Next
Thank you.
Would you please help how to fill it to fill to datagridview ?
For Each dtTable As DataTable In dsTables.Tables
Dim dgvRow As New DataGridViewRow
Dim dgvCell As DataGridViewCell
dgvCell = New DataGridViewTextBoxCell()
-------> dgvCell.Value = dtTable.n
dgvRow.Cells.Add(dgvCell)
dgvTables.Rows.Add(dgvRow)
Next
Thank you.
It should be like what you had above:
Dim dsTables As New DataSet
Dim strXMLFileName As String = strSourceFromClientFolder & "121110110334.xml"
dsTables.ReadXml(strXMLFileName)
dgvTables.DataSource = dsTables
ASKER
I've tried it.
The grid show nothing ?
Thank you.
The grid show nothing ?
Thank you.
ASKER
I've got it.
dgvTables.Columns.Add("Tab le", "Table")
For Each tbl As DataTable In dsTables.Tables
Dim dgvRow As New DataGridViewRow
Dim dgvCell As DataGridViewCell
dgvCell = New DataGridViewTextBoxCell()
dgvCell.Value = tbl.TableName
dgvRow.Cells.Add(dgvCell)
dgvTables.Rows.Add(dgvRow)
Next
Thank you very much for your help.
dgvTables.Columns.Add("Tab
For Each tbl As DataTable In dsTables.Tables
Dim dgvRow As New DataGridViewRow
Dim dgvCell As DataGridViewCell
dgvCell = New DataGridViewTextBoxCell()
dgvCell.Value = tbl.TableName
dgvRow.Cells.Add(dgvCell)
dgvTables.Rows.Add(dgvRow)
Next
Thank you very much for your help.
Awesome! Glad to help = )
Open in new window