Solved

READ DATA FROM MULTIPLE TABLES FROM XML

Posted on 2011-03-17
6
409 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now