Solved

READ DATA FROM MULTIPLE TABLES FROM XML

Posted on 2011-03-17
6
411 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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