[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

READ MULTIPLE TABLES OF XML FILE TO DATASET

Posted on 2011-03-17
8
Medium Priority
?
687 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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