Solved

READ DATA FROM MULTIPLE TABLES FROM XML

Posted on 2011-03-17
6
416 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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