列表视图中的项目加载未显示

时间:2015-03-07 20:11:14

标签: vb.net listview ms-access-2003

我在查看listview中的项目时遇到问题 这是我的代码

rs.Open("select tableStudentRecords.*, tableTransaction.*, tablePayments.* from tableStudentRecords, tableTransaction , tablePayments" & _ " where tableStudentRecords.studnum = tableTransaction.studnum and tablePayments.psitscode = tableTransaction.psitscode", con, 3, 3) Dim i As Integer = 0 With lvPaymentRecords Do Until rec.EOF .Items.Add(rec("tableTransaction.studnum").Value) x = rec("sname").Value & ", " & rec("fname").Value & " " & rec("mi").Value & " " & rec("ext").Value .Items(i).SubItems.Add(x) lvPaymentRecords.Items(i).SubItems.Add(rec("sem").Value) .Items(i).SubItems.Add(rec("sy").Value) .Items(i).SubItems.Add(rec("total").Value) i = i + 1 rec.MoveNext() Loop End With rec.Close() con.Close()

问题是,项目不会出现在listview中,我不知道是什么原因, tableStudentRecords和tablePayments都是PRIMARY键, 这是数据库关系 (对不起,由于声誉不佳,我无法发布图片)

tableStudentRecords _____ tableTransaction _____ tablePAyments

-studnum _____________ -psitscode _____________- psitscode

-sname _______________ -studnum ____________- sem

-fname ________________ -sy __________________- payname

-gndr __________________-总_______________-金额

我只需要在listview加载中查看tablePayments的sem,

1 个答案:

答案 0 :(得分:0)

您必须声明ListViewItem变量。代码应该是

 Dim lpRec As ListViewItem
    With lvPaymentRecords
        Do Until rec.EOF
            lpRec=.Items.Add(rec("tableTransaction.studnum").Value)
            x = rec("sname").Value & ", " & rec("fname").Value & " " & rec("mi").Value & " " & rec("ext").Value
            lpRec.SubItems.Add(x)
            lpRec.SubItems.Add(rec("sem").Value)
            lpRec.Items(i).SubItems.Add(rec("sy").Value)
            lpRec.Items(i).SubItems.Add(rec("total").Value)
            i = i + 1
            rec.MoveNext()
        Loop
    End With
    rec.Close()
    con.Close()

希望它可以帮到你。