Solved

READ DATA FROM MULTIPLE TABLES FROM XML

Posted on 2011-03-17
6
414 Views
Last Modified: 2012-05-11
Hi All,

I have read data from xml into dataset and fill it into gridview, let's call it dgvTables.

Now I want to show its table data to dgvData when user click the dgvTables.

Below is my attempt, but fail.

How could I do it ?

Thank you.

Private Sub dgvTables_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgvTables.Click
        dgvData.DataSource = Nothing

        strFileName = dgvTables.CurrentRow.Cells("Table").Value.ToString.Trim

        dgvData.DataSource = dsTables.Tables(strFileName)

    End Sub

Open in new window

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
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35166709
Hi,

What error gives you? how are you filling the dsTables Dataset?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35166741
Hi gamarrojgq,

Please below code and xml file.

Thank you.
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim dsTables As New DataSet

        Try

            Dim strSourceFromClientFolder As String = System.AppDomain.CurrentDomain.BaseDirectory()
            Dim strXMLFileName As String = strSourceFromClientFolder & "121110110334.xml"

            dsTables.ReadXml(strXMLFileName)

            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

        Catch ex As Exception
            MsgBox("Gagal Buka XML File ...!", MsgBoxStyle.Information, Me.Text)
        End Try

    End Sub

Open in new window

121110110334.xml
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35166822
ok, and what is the error  that gives you?
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
LVL 1

Author Comment

by:emi_sastra
ID: 35166851
No, error.

There is one more datagridview called dgvData.

I want to do like something below.


  Private Sub dgvTables_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgvTables.Click
        dgvData.DataSource = Nothing

        strFileName = dgvTables.CurrentRow.Cells("Table").Value.ToString.Trim

        dgvData.DataSource = dsTables.Tables(strFileName)

    End Sub


Thank you.
0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35166940
Ok, you should do the follow

1.- instead of declaring the object  dsTables on the FORM LOAD event, you should declare it at the top of your class, just after the Class name like this

Public Class YOURCLASSNAME

Private dsTables As New DataSet

2.- use CELLCLICK event,  and should be something like this

    Private Sub dgvTables_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick

        Dim strFileName As String
        strFileName = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString.Trim

        dgvData.DataSource = Nothing
        dgvData.DataSource = dsTables.Tables(strFileName)

    End Sub
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35167010
I see it now.

Thank you very much for your help.
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

759 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