Question : VB .NET 2005 Combine Two Tables on Primary Key and Display in DataGridView

I have created two datasets from two queries pulling from two different sources, which I cannot join or union.  These results of the query have different schema and structure, yet they have the same primary key.  I would like to display all fields from both datasets in one datagrid.  (Please no replies stating the best way is to join\union with a query, need a vb .net 2005 programming solution)  Thanks!

Answer : VB .NET 2005 Combine Two Tables on Primary Key and Display in DataGridView

Sorry I didn't realize that you try this before. Try to do something like this then (look at the Code):

The Idea is get  Table1 in 1 dataset then look throught the second and add the fields that you want to the first one from the second table if find the same index. I do this with SQL before

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
        Dim Table1 As New DataTable
        Dim AdTable1 As New SqlDataAdapter("SELECT * from Table1", Me.ConSQL)
        Table1.Clear()
        AdTable1.Fill(Table1)
        Table1.Rows.Add("Table2_Colums1_To_Add")
        Table1.Rows.Add("Table2_Colums2_To_Add")

        Dim I, IdT1, Qry
        For I = 0 To Table1.Rows.Count - 1
            IdT1 = Table1.Rows(I).Item("Id")
            Qry = "Select * from Table2 where IdT2='" & IdT1 & "'"
            Dim Table2 As New DataTable
            Dim AdTable2 As New SqlDataAdapter(Qry, Me.ConSQL)
            Table2.Clear()
            AdTable2.Fill(Table2)
            If Table2.Rows.Count > 0 Then
                Table1.Rows(I).BeginEdit()
                Table1.Rows(I).Item("Table2_Colums1") = Table2.Rows(0).Item("Table2_Colums1")
                Table1.Rows(I).Item("Table2_Colums2") = Table2.Rows(0).Item("Table2_Colums2")
                Table1.Rows(I).AcceptChanges()
            End If
        Next
Me.Datagridview1.Datasource=Table1
Me.datagridview1.refresh
Random Solutions  
 
programming4us programming4us