vb listview显示数据库内容
我想用listview显示数据库的内容,但执行之后,listview一片空白。
我的代码是
Private Sub Form_Load()
Dim str As String
Set conn = New ADODB.Connection
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dm.mdb;Persist Security Info=False"
conn.Open str
Dim rs1 As ADODB.Recordset
Set rs1 = New ADODB.Recordset
ListView1.View = lvwReport
ListView1.Gridlines = True
ListView1.FullRowSelect = True
With ListView1
.View = lvwReport
.ColumnHeaders.Add = "资产标志"
.ColumnHeaders.Add = "资产编号"
.ColumnHeaders.Add = "资产名称"
.ColumnHeaders.Add = "品名"
.ColumnHeaders.Add = "厂家"
.ColumnHeaders.Add = "型号"
.ColumnHeaders.Add = "配置"
.ColumnHeaders.Add = "数量"
.ColumnHeaders.Add = "购进单位"
.ColumnHeaders.Add = "使用人"
.ColumnHeaders(1).Width = 1000
.ColumnHeaders(1).Width = 1500
.ColumnHeaders(1).Width = 2000
.ColumnHeaders(1).Width = 1500
.ColumnHeaders(1).Width = 1500
.ColumnHeaders(1).Width = 1500
.ColumnHeaders(1).Width = 1500
.ColumnHeaders(1).Width = 800
.ColumnHeaders(1).Width = 2500
.ColumnHeaders(1).Width = 1000
End With
Dim addlist As ListItem
Dim i As Integer
rs1.Open "select * from sbjbztb", conn, 1, 1
Do While rs1.EOF
Set addlist = ListView1.ListItems.Add(, , rs1.Fields("id").Value)
addlist.SubItems(1) = IIf(IsNull(rs1.Fields("资产编号").Value), "", rs1.Fields("资产编号").Value)
addlist.SubItems(2) = IIf(IsNull(rs1.Fields("资产编号").Value), "", rs1.Fields("资产编号").Value)
addlist.SubItems(3) = IIf(IsNull(rs1.Fields("资产名称").Value), "", rs1.Fields("资产名称").Value)
addlist.SubItems(4) = IIf(IsNull(rs1.Fields("品名").Value), "", rs1.Fields("品名").Value)
addlist.SubItems(5) = IIf(IsNull(rs1.Fields("厂家").Value), "", rs1.Fields("厂家").Value)
addlist.SubItems(6) = IIf(IsNull(rs1.Fields("型号").Value), "", rs1.Fields("型号").Value)
addlist.SubItems(7) = IIf(IsNull(rs1.Fields("配置").Value), "", rs1.Fields("配置").Value)
addlist.SubItems(8) = IIf(IsNull(rs1.Fields("数量").Value), "", rs1.Fields("数量").Value)
addlist.SubItems(9) = IIf(IsNull(rs1.Fields("购进单位").Value), "", rs1.Fields("购进单位").Value)
addlist.SubItems(10) = IIf(IsNull(rs1.Fields("使用人").Value), "", rs1.Fields("使用人").Value)
rs1.MoveNext
Loop
rs1.close
End Sub
请大家帮我看看,是哪里出了问题。
[解决办法]
Do While rs1.EOF写错了
改为:Do While not rs1.EOF