Solved

READ DATA FROM MULTIPLE TABLES FROM XML

Posted on 2011-03-17
6
412 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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