0

我正在尝试将 MS Access 数据库中的项目显示到列表视图中,但由于某些奇怪的原因,我无法找出原因,我的列表视图确实显示了所有记录,但它使一些记录为空白

在此处输入图像描述

这是我用来加载我的项目的子:

    Public Sub LoadItems()

    If tcOverzicht.SelectedIndex = 0 Then
        Dim strQuery As String = "SELECT tblItems.itemID, tblItems.Referentie, tblType.Type, tblItems.Stock, tblItems.Barcode, tblItems.Omschrijving, tblItems.Merk, tblItems.Opmerking " & _
                                 "FROM tblItems INNER JOIN tblType ON tblItems.typeID = tblType.typeID WHERE tblItems.typeID=" & intType & ";"
        Dim da As New OleDbDataAdapter
        Dim cmd As New OleDbCommand(strQuery, cnConnectie)
        Dim TABLE As New DataTable

        With da
            .SelectCommand = cmd
            .Fill(TABLE)
        End With

        'Listview leeg maken
        lvItems.Items.Clear()

        'Listview vullen met de gegevens uit de DB
        For i As Integer = 0 To TABLE.Rows.Count - 1
            With lvItems
                .Items.Add(TABLE.Rows(i)("itemID"))
                With .Items(.Items.Count - 1).SubItems
                    .Add(TABLE.Rows(i)("Referentie"))
                    .Add(TABLE.Rows(i)("Type"))
                    .Add(TABLE.Rows(i)("Stock"))
                    .Add(TABLE.Rows(i)("Barcode"))
                    .Add(TABLE.Rows(i)("Omschrijving"))
                    .Add(TABLE.Rows(i)("Merk"))
                    .Add(TABLE.Rows(i)("Opmerking"))
                End With
            End With
        Next
    End If

    If tcItems.SelectedIndex = 0 Then
        Dim strQuery As String = "SELECT tblItems.itemID, tblItems.Referentie, tblType.Type, tblItems.Stock, tblLeveranciers.Leverancier, tblItems.Barcode, tblItems.MinStuks,tblItems.Omschrijving, tblItems.Merk,  tblItems.Opmerking " & _
                                 "FROM (tblItems INNER JOIN tblLeveranciers ON tblItems.leveranciersID = tblLeveranciers.leveranciersID) INNER JOIN tblType ON tblItems.typeID = tblType.typeID;"

        Dim da As New OleDbDataAdapter
        Dim cmd As New OleDbCommand(strQuery, cnConnectie)
        Dim TABLE As New DataTable

        With da
            .SelectCommand = cmd
            .Fill(TABLE)
        End With

        'Listview leeg maken
        lvArtikel.Items.Clear()

        'Listview vullen met de gegevens uit de DB
        For i As Integer = 0 To TABLE.Rows.Count - 1
            With lvArtikel
                .Items.Add(TABLE.Rows(i)("itemID"))
                With .Items(.Items.Count - 1).SubItems
                    .Add(TABLE.Rows(i)("Referentie"))
                    .Add(TABLE.Rows(i)("Type"))
                    .Add(TABLE.Rows(i)("Stock"))
                    .Add(TABLE.Rows(i)("Leverancier"))
                    .Add(TABLE.Rows(i)("Barcode"))
                    .Add(TABLE.Rows(i)("MinStuks"))
                    .Add(TABLE.Rows(i)("Omschrijving"))
                    .Add(TABLE.Rows(i)("Merk"))
                    .Add(TABLE.Rows(i)("Opmerking"))
                End With
            End With
        Next
    End If

End Sub

我完全迷路了..也许你们中的一些人知道为什么?

问候

4

1 回答 1

0

您可以在手动将列添加到 listView 后使用此代码。

For i As Integer = 0 To TABLE.Rows.Count - 1
    Dim str(7) As String
    Dim itm As ListViewItem
    str(0) = TABLE.Rows(i)("itemID")
    str(1) = TABLE.Rows(i)("Referentie")
    str(2) = TABLE.Rows(i)("Type")
    str(3) = TABLE.Rows(i)("Stock")
    str(4) = TABLE.Rows(i)("Barcode")
    str(5) = TABLE.Rows(i)("Omschrijving")
    str(6) = TABLE.Rows(i)("Merk")
    str(7) = TABLE.Rows(i)("Opmerking")
    itm = New ListViewItem(str)
    listView.Items.Add(itm)
Next
于 2013-03-29T12:18:50.077 回答