[求助]把数据库的记录赋值给一个数组
大家好!我有一个数据库,Access2000格式的,里面有五个表,每个表里有250个字段,我要把数据赋值给一个数组,字段为data0~data249,我找了好多书,找不到把数据赋值给变量的方法,
怎么实现啊,请高手指点哦.
先谢谢了!
1 先打开数据库,应该会吧!
Dim i%,j%,z!(),m%,n%
Dim mlink As String, mpath As String, macc As String
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
mlink = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= data.mdb"
macc = "select * from shuju"
Cnn.Open mlink
Set Rst = New ADODB.Recordset
Rst.Open macc, Cnn, adOpenKeyset, adLockOptimistic
2 获得表的字段数和记录数
Rst.MoveLast
i = Rst.RecordCount - 1
j = Rst.Fields.Count - 1
3 利用循环赋值
ReDim z(i, j)
For m = 0 To i
If m > 0 Then
Rst.MoveNext
If Rst.EOF Then
Rst.MoveLast
End If
Else
Rst.MoveFirst
End If
For n = 0 To j
z(m, n) = Rst.Fields(n)
Print z(m, n);
Next n
Print
Next m
Cnn.Close
差不多了吧!