?
Solved

READ MULTIPLE TABLES OF XML FILE TO DATASET

Posted on 2011-03-17
8
Medium Priority
?
685 Views
Last Modified: 2012-05-11
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.
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

Open in new window

121110110334.xml
0
Comment
Question by:emi_sastra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35156201
Works fine for me with just this:
Dim dsTables As DataSet = Nothing
Dim strXMLFileName As String = strSourceFromClientFolder & "121110110334.xml"

dsTables.ReadXml(strXMLFileName)

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35156482
Very weird.

I've got exception "object reference not set to an instance of object" at :

dsTables.ReadXml(strXMLFileName)

Why is that ?

Thank you.


0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35156585
Heheh...   noob mistake on my part. Initialize the dataset:
Dim dsTables As New DataSet
Dim strXMLFileName As String = strSourceFromClientFolder & "121110110334.xml"

dsTables.ReadXml(strXMLFileName)

Open in new window

0
A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

 
LVL 1

Author Comment

by:emi_sastra
ID: 35156690
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.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35156774
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

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35156852
I've tried it.

The grid show nothing ?

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35157048
I've got it.

 dgvTables.Columns.Add("Table", "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.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35157083
Awesome! Glad to help  = )
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question