读书人

VB中对rs产生的结果处理,该如何处理

发布时间: 2012-03-08 13:30:13 作者: rapoo

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语句遍历这些记录


[解决办法]

VB code
dim i as longRs.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 iElse '查询结果不存在记录    FAuxprice = 0End IfRs.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

读书人网 >VB

热点推荐