0

这个问题让我发疯,我无法弄清楚为什么会这样。我正在使用 vb.net 在访问数据库中运行查询,然后将数据放入列表视图中。代码:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim strAccessConn As String = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = T:\mydb.accdb"
    Dim cn As OleDbConnection = New OleDbConnection(strAccessConn)
    Dim ds As New DataSet
    Dim dt As DataTable

    'Note the query is entered as a string.
    Dim da As New OleDbDataAdapter("Q_LIST", cn) 'is the name of the query in Access 

    'Set the CommandType of the SelectCommand to TableDirect
    da.SelectCommand.CommandType = CommandType.TableDirect
    da.Fill(ds, "mytable")
    dt = ds.Tables("mytable")

    ListViewBatchResults.MultiSelect = True
    ListViewBatchResults.View = View.Details
    ListViewBatchResults.GridLines = True
    ListViewBatchResults.Columns.Clear()
    ListViewBatchResults.Items.Clear()

    For Each col As DataColumn In dt.Columns()
        ListViewBatchResults.Columns.Add(col.ToString)
    Next

    MsgBox(dt.Rows.Count)

    For Each row As DataRow In dt.Rows()

        Dim lst As ListViewItem

        lst = ListViewBatchResults.Items.Add(row(0))

        For i As Integer = 1 To dt.Columns.Count - 1
            lst.SubItems.Add(row(i))
        Next

    Next


End Sub

虽然这个列表视图并没有显示所有返回的数据,但我不知道为什么 - 它适用于数据库中的其他查询,但由于某种原因不适用于这个查询。行数显示有 264 行,但是当我运行项目时,列表视图仅显示其中 3 行。到底他妈发生了什么?

干杯!

4

1 回答 1

0
Dim lst As ListViewItem

Dim lst As New ListViewItem
于 2013-08-09T19:56:19.283 回答