如何把sql查询结果放到数组中
用VB连接SQL数据库如题sql语句selectidfromtable如何把查询到的ID放到数组中存放,使下面用到时能直接调用数组...
用VB连接SQL数据库
如题
sql语句 select id from table
如何把查询到的ID放到数组中存放,使下面用到时能直接调用数组 展开
如题
sql语句 select id from table
如何把查询到的ID放到数组中存放,使下面用到时能直接调用数组 展开
展开全部
Private Sub Command1_Click()
Dim conn As ADODB.Connection
Dim Rs As ADODB.Recordset
Set conn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.Recordset")
conn.Open "provider=microsoft.jet.oledb.4.0;data source=d:\db1.mdb"
Rs.Open "select id from table1", conn, 1, 3
''''''''''''''以上不是重点,只是为了链接数据库
Dim a() As Long'定义a数组
Dim l As Long
l = 0
While Not Rs.EOF
ReDim Preserve a(0 To l) As Long '重定义数组大小
a(l) = Rs("id") '保存新数据
l = l + 1
Rs.MoveNext
Wend
'''''''''''''''''''以下也不是重点
Rs.Close
conn.Close
Set conn = Nothing
Set Rs = Nothing
For l = 0 To UBound(a)
Print a(l);
Next l
End Sub
Dim conn As ADODB.Connection
Dim Rs As ADODB.Recordset
Set conn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.Recordset")
conn.Open "provider=microsoft.jet.oledb.4.0;data source=d:\db1.mdb"
Rs.Open "select id from table1", conn, 1, 3
''''''''''''''以上不是重点,只是为了链接数据库
Dim a() As Long'定义a数组
Dim l As Long
l = 0
While Not Rs.EOF
ReDim Preserve a(0 To l) As Long '重定义数组大小
a(l) = Rs("id") '保存新数据
l = l + 1
Rs.MoveNext
Wend
'''''''''''''''''''以下也不是重点
Rs.Close
conn.Close
Set conn = Nothing
Set Rs = Nothing
For l = 0 To UBound(a)
Print a(l);
Next l
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询