我正在尝试将 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
我完全迷路了..也许你们中的一些人知道为什么?
问候