1

我正在尝试合并两行并将其写入第三个表上的新行:

例子:

表A:(数据固定)

客户 | 姓名 | 姓
 1 | 鲍勃 | 詹森斯
 2 | 一月 | 彼得斯
... | ... | ...

表B:(数据固定)

年龄 | 长度 | 重量
 23 | 178 | 76
 75 | 165 | 86
... | ... | ...

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

表C:

客户 | 姓名 | 姓氏 | 年龄 | 长度 | 重量
 1 | 鲍勃 | 詹森 | 23 | 178 | 76
 2 | 一月 | 皮特斯 | 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

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

4

1 回答 1

0

您可以使用 SQL 服务器“视图”

在此处输入图像描述

为此,只需将两个表拖放到窗格中并加入它们

于 2020-04-07T12:26:43.597 回答