将2个独立的datagridviewrows中的2行合并为一个新的vb.net

时间:2014-10-07 12:38:57

标签: vb.net csv datagridview datagridviewrow

我试图合并两行并将其写入第三个表的新行:

示例:

表A :(数据是固定的)

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

表B :(数据是固定的)

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

现在,这两个表需要像这样合并:

表C:

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

我的代码现在,甚至不工作:

    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

有人知道如何实现这个目标吗?

1 个答案:

答案 0 :(得分:0)

您可以使用SQL Server“视图”

enter image description here

要实现此目的,只需将两个表拖放到窗格中并加入它们