在datagridview vb.net中添加一行

时间:2018-02-26 16:37:19

标签: vb.net ms-access datagridview

我想在datagridview中向用户显示文章信息的来源(famille1或famille2):

我的代码:

Dim dt1 As DataTable = New db_con().selectdata( _
              "SELECT famille1.ID, famille1.Article, famille1.quantité, famille1.prixch, famille1.prixvn, famille1.dateex FROM famille1;")
        Dim dt2 As DataTable = New db_con().selectdata( _
              "SELECT famille2.ID, famille2.Article, famille2.quantité, famille2.prixch, famille2.prixvn, famille2.dateex FROM famille2;")

        DataGridView1.Rows.Clear()
        For i As Integer = 0 To dt1.Rows.Count - 1
            DataGridView1.Rows.Add(i + 1, dt1.Rows(i)(0), dt1.Rows(i)(1), dt1.Rows(i)(2), dt1.Rows(i)(3), dt1.Rows(i)(4), dt1.Rows(i)(5))
        Next
        For i As Integer = 0 To dt2.Rows.Count - 1
            DataGridView1.Rows.Add(i + 1, dt2.Rows(i)(0), dt2.Rows(i)(1), dt2.Rows(i)(2), dt2.Rows(i)(3), dt2.Rows(i)(4), dt2.Rows(i)(5))
        Next

我认为代码应该是这样的:

Dim dt1 As DataTable = New db_con().selectdata( _
              "SELECT famille1.ID, famille1.Article, famille1.quantité, famille1.prixch, famille1.prixvn, famille1.dateex FROM famille1;")
        Dim dt2 As DataTable = New db_con().selectdata( _
              "SELECT famille2.ID, famille2.Article, famille2.quantité, famille2.prixch, famille2.prixvn, famille2.dateex FROM famille2;")

        DataGridView1.Rows.Clear()
        For i As Integer = 0 To dt1.Rows.Count - 1
            DataGridView1.Rows.Add(i + 1, dt1.Rows("famille1"), dt1.Rows(i)(0), dt1.Rows(i)(1), dt1.Rows(i)(2), dt1.Rows(i)(3), dt1.Rows(i)(4), dt1.Rows(i)(5))
        Next
        For i As Integer = 0 To dt2.Rows.Count - 1
            DataGridView1.Rows.Add(i + 1, dt1.Rows("famille2"), dt2.Rows(i)(0), dt2.Rows(i)(1), dt2.Rows(i)(2), dt2.Rows(i)(3), dt2.Rows(i)(4), dt2.Rows(i)(5))
        Next

所以,我想在Datagridview中连续显示数据来源(famille1或famille2)

希望很清楚:/

0 个答案:

没有答案