VB中对rs产生的结果处理,该如何处理
VB中对rs产生的结果处理
Rs.Open "select FItemID as FAuxprice from Icstockbillentry t1" + vbLf + _
"where t1.FInterID='1938' "
If Rs.RecordCount > 0 Then '如果查询结果存在记录
FAuxprice = Rs("FAuxprice")
MsgBox FAuxprice
Else '查询结果不存在记录
FAuxprice = 0
End If
Rs.Close
其中Rs有多条记录,我想对这个结果集所有的记录放在一个组内,用For语句遍历这些记录
------解决方案--------------------
Rs.Open "select FItemID as FAuxprice from Icstockbillentry t1" + vbLf + _
"where t1.FInterID='1938' "
If Rs.RecordCount > 0 Then '如果查询结果存在记录
FAuxprice = Rs("FAuxprice")
MsgBox FAuxprice
Else '查询结果不存在记录
FAuxprice = 0
End If
Rs.Close
其中Rs有多条记录,我想对这个结果集所有的记录放在一个组内,用For语句遍历这些记录
------解决方案--------------------
- VB code
dim i as long Rs.Open "select FItemID as FAuxprice from Icstockbillentry t1" + vbLf + _ "where t1.FInterID='1938'",conn,adopenkeyset,adlockreadonly If Rs.RecordCount > 0 Then '如果查询结果存在记录 for i=1 to rs.recordcount tmp(i-1)=rs!FAuxprice rs.movenext next i Else '查询结果不存在记录 FAuxprice = 0 End If Rs.Close
------解决方案--------------------
dim i as long
dim tmp() as long
Rs.Open "select FItemID as FAuxprice from Icstockbillentry t1" + vbLf + _
"where t1.FInterID='1938'",conn,adopenkeyset,adlockreadonly
with rs
If not .eof Then '如果查询结果存在记录
do while Not .EOF
tmp(i)=.Fields("FAuxprice")
i=i+1
rs.movenext
Loop
Else '查询结果不存在记录
FAuxprice = 0
End If
end with
Rs.Close