现在用vb+access,查询,将结果显示到listview中,现在我做
Set rst = db.OpenRecordset("select * from dangqian where(lot='13')")
这个。然后显示的只有一条记录,应该有很多条的,请高手指点。
如何实现多条件查询呢?包括一个时间段的查询,谢谢。
Set rst = db.OpenRecordset("select * from dangqian where(lot='13')")
这个。然后显示的只有一条记录,应该有很多条的,请高手指点。
如何实现多条件查询呢?包括一个时间段的查询,谢谢。
Set rst = db.OpenRecordset("select * from dangqian where(lot='13')")
LV1.ListItems.Clear
For i = 1 To rst.RecordCount
LV1.ListItems.Add i, , rst.Fields("Lot") & vbNullString
With LV1.ListItems(i)
.SubItems(1) = rst.Fields("1") & vbNullString
.SubItems(2) = rst.Fields("2") & vbNullString
.SubItems(3) = rst.Fields("3") & vbNullString
End With
rst.MoveNext
If rst.EOF Then Exit For
Next irst.Close
db.Close
LV1.ListItems.Add i, , rst.Fields("Lot") & vbNullString
With LV1.ListItems(i)
.SubItems(1) = rst.Fields("1") & vbNullString
.SubItems(2) = rst.Fields("2") & vbNullString
.SubItems(3) = rst.Fields("3") & vbNullString
End With
rst.MoveNext
'If rst.EOF Then Exit For '去掉
Next i
.SubItems(1) = rst.Fields("1") & vbNullString '1是字段名? 如果是序号,不需要双引号且序号从0开始
.SubItems(2) = rst.Fields("2") & vbNullString
.SubItems(3) = rst.Fields("3") & vbNullString
多条件是指什么样的?e.g.
select * from dangqian where lot='13' and 字段2>0 and 字段3 is not null
这是我的
If rst.State Then
rst.Close
Set rst = Nothing
End If
rst.CursorLocation = adUseClient然后再添加你自己的代码试试
Set rst = db.OpenRecordset("select * from dangqian where(lot='13')")
LV1.ListItems.Clear
For i = 1 To rst.RecordCount
Do While Not rss.EOF
For i = 1 To rss.RecordCount
Set Fliv = ListView1.ListItems.Add()
Fliv.Text = i
Fliv.SubItems(1) = rss.Fields("字段1")
Fliv.SubItems(2) = rss.Fields("字段2")
Fliv.SubItems(3) = rss.Fields("字段3")
Fliv.SubItems(4) = rss.Fields("字段4")
Fliv.SubItems(5) = rss.Fields("字段5")
rss.MoveNext
Next i
Loop
rss.Close