Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
lblT1.Caption = rs.Fields(0) 这种方法好像不行;
lblT2.Caption =
lbl3.Caption =
lblT4.Caption =
lblT5.Caption =
lblT6.Caption =
End Sub
我的目的是,将表中的Qcontent 字段赋值给lblT1....lblT20 , 我现在从数据库中随即取出了20条数据,如何赋值给到label中呢,
3 个解决方案
#1
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
if not rs.eof then
lblT1.Caption = rs(0) 这种方法好像不行;
lblT2.Caption =
lbl3.Caption =
lblT4.Caption =
lblT5.Caption =
lblT6.Caption =
end if
end sub
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
if not rs.eof then
lblT1.Caption = rs(0) 这种方法好像不行;
lblT2.Caption =
lbl3.Caption =
lblT4.Caption =
lblT5.Caption =
lblT6.Caption =
end if
end sub
#2
Private Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
lblT1.Caption = rs("Qcontent")
rs.movenext
lblT2.Caption =rs("Qcontent")
.................
lbl3.Caption =
lblT4.Caption =
lblT5.Caption =
lblT6.Caption =
End Sub
这样最好建立控件数组lblT(19)
Private Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
for i=0 to 19
lblT(i).Caption = rs("Qcontent")
rs.movenext
next i
End Sub
#3
lz是最佳答案
这样最好建立控件数组lblT(19)
VB codePrivate Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
for i=0 to 19
lblT(i).Caption = rs("Qcontent")
rs.movenext
next i
End Sub
这样最好建立控件数组lblT(19)
VB codePrivate Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
for i=0 to 19
lblT(i).Caption = rs("Qcontent")
rs.movenext
next i
End Sub
#1
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
if not rs.eof then
lblT1.Caption = rs(0) 这种方法好像不行;
lblT2.Caption =
lbl3.Caption =
lblT4.Caption =
lblT5.Caption =
lblT6.Caption =
end if
end sub
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
if not rs.eof then
lblT1.Caption = rs(0) 这种方法好像不行;
lblT2.Caption =
lbl3.Caption =
lblT4.Caption =
lblT5.Caption =
lblT6.Caption =
end if
end sub
#2
Private Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
lblT1.Caption = rs("Qcontent")
rs.movenext
lblT2.Caption =rs("Qcontent")
.................
lbl3.Caption =
lblT4.Caption =
lblT5.Caption =
lblT6.Caption =
End Sub
这样最好建立控件数组lblT(19)
Private Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
for i=0 to 19
lblT(i).Caption = rs("Qcontent")
rs.movenext
next i
End Sub
#3
lz是最佳答案
这样最好建立控件数组lblT(19)
VB codePrivate Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
for i=0 to 19
lblT(i).Caption = rs("Qcontent")
rs.movenext
next i
End Sub
这样最好建立控件数组lblT(19)
VB codePrivate Sub btn_ChuTi_Click()
Dim rs As New ADODB.Recordset
Sql = "select top 20 Qcontent,Qanswer from TbmQusetions order by newID() desc" '把查询用户信息的SQL语句赋给变量Sql
rs.Open Sql, cnn, adOpenStatic, adLockBatchOptimistic '以只读的方式静态的打开Sql执行的结果的记录集
rs.movefirst
for i=0 to 19
lblT(i).Caption = rs("Qcontent")
rs.movenext
next i
End Sub