VB如何获取select返回值

来源:百度知道 编辑:UC知道 时间:2024/05/16 02:34:32
strsql = "select name from table1 where sex='1'"
Set rs = New ADODB.Recordset
rs.Open strsql, conn, adOpenDynamic, adLockOptimistic
Label1.Caption = rs.Fields("ID")

table1中结构如下
name sex
tom 1
jerry 1
lucy 0
merry 0

Label1.Caption只取得tom一个值,
请问,如何把所有符合条件的值都取到?
写错了,第4行为Label1.Caption = rs.Fields("name")

我刚学,怎么写代码啊?

还是不行啊,我上面的代码需要改吗?在哪里改?

其实就是循环遍历每一个记录就行在rs.open...下面添加
例如
for i =0 to rs.RecordCount -1
Label1.Caption = rs.Fields("name")
rs.movenext
next
这里不推荐用Label1显示,那样显示成一串了最好用Combo或者list这类控件显示,使用
list1.AddItem rs.Fields("name")

while not rs.eof
Label1=Label1.caption & rs.Fields("name") & " "
rs.movenext
wend
Label1.AutoSize = True

dim i as Integer
For i = 1 To rs.recordcount
Label1=Label1.caption & rs.Fields("name") & " "
rs.movenext
Next

Label1.AutoSize = True

循环记录集啊

dim i as Integer
For i = 1 To rs.recordcount
Label1=Label1& rs.Fields("name") & " "
rs.movenext
Next