1

I'm trying to merge two rows and write it to a new row on a third table:

Example:

TableA: (data is fixed)

 customer | name | last name
 1        | bob  | jansens
 2        | jan  | peeters
...       | ...  | ...

TableB: (data is fixed)

 age      | lenght | weight
 23       | 178    | 76
 75       | 165    | 86
...       | ...    | ...

Now, those two tables need to be merged like so:

TableC:

 customer | name | last name |  age   | lenght | weight
 1        | bob  | jansens   |  23    | 178    | 76
 2        | jan  | peeters   |  75    | 165    | 86
...       | ...  | ...       | ...    | ...    | ...

My code for now, even not working:

    Public Sub merge_BAK(adminis As DataGridView, kluwer As DataGridView, merged As DataGridView)
    Dim adminis_header_count As Integer = adminis.Columns.Count
    Dim kluwer_header_count As Integer = kluwer.Columns.Count
    Dim diff_header_count As Integer = kluwer.Columns.Count - adminis.Columns.Count
    Dim total_header_count As Integer = adminis_header_count + kluwer_header_count
    For Each adminis_row As DataGridViewRow In adminis.Rows
        If adminis_row.IsNewRow = False Then

            Dim btw As String = adminis_row.Cells(4).Value()

            If btw IsNot String.Empty Then
                btw = btw.Remove(0, 3)


                For Each kluwer_row As DataGridViewRow In kluwer.Rows
                    Dim venn_onderneming As String = kluwer_row.Cells(44).Value()
                    If btw = venn_onderneming Then

                        merged.ColumnCount = total_header_count

                        Dim merge_row As DataGridViewRow = CType(adminis_row.Clone(), DataGridViewRow)
                        For i As Integer = 0 To adminis_row.Cells.Count - 1
                            merge_row.Cells(i).Value = adminis_row.Cells(i).Value
                        Next

                        merged.Rows.Add(merge_row) 'somewhere here the current row (kluwer_row) needs to be placed behind the current row of the previous table (adminis_row)

                    End If
                Next kluwer_row
            End If
        End If
    Next adminis_row
End Sub

Does anybody have an idea how to achieve this?

ci_
  • 8,594
  • 10
  • 39
  • 63
krstfvndm
  • 143
  • 1
  • 7

1 Answers1

0

You can use SQL server "VIEWs"

enter image description here

To achieve that, just drag and drop both tables in your pane and join them

jose praveen
  • 1,298
  • 2
  • 10
  • 17