我在这里面临一个无聊的问题...
我正在尝试将记录集转换为数组,但对象类型未返回correctl
我有一个Recordset类型函数,我尝试通过记录集对象接收此函数的结果。但是当我尝试测试对象类型时,typeof函数返回“Fields”类型。
搜索方法:
Public Function Buscar(ByVal query As String) As Recordset
Dim rs As New Recordset
If con.State <> 1 Then
Conectar
End If
rs.Open query, con, adOpenStatic, adLockReadOnly
Set Buscar = rs
End Function
dim r as recordset
dim c as new clsConnection
r = c.buscar("select * from costumers")
c.casttoarray(r)
Private Sub castToArray(obj As Object)
Dim rs As New Recordset
Dim linhas() As String
Dim colsize() As Integer
Dim aux As Integer
If TypeOf obj Is adodb.Recordset Then
Dim nLin As Long
Dim nCol As Integer
Dim l As Long
Dim c As Integer
Set rs = obj
colsize = capturarLimites(rs)
nLin = rs.RecordCount
nCol = rs.Fields.Count
ReDim linhas(nLin)
rs.MoveFirst
For l = 0 To nLin - 1
For c = 0 To nCol - 1
aux = colsize(c) - Len(rs.Fields(c).Value)
linhas(l) = linhas(l) & "" & rs.Fields(c).Value & rptString(" ", aux + 1)
Next c
Next l
End If
End Sub
答案 0 :(得分:1)
问题是调用 Sub 时使用的括号:
c.casttoarray (r)
这些评估r
,因此将Recordset类的默认成员(即Fields集合)传递给过程。
删除它们或使用电话;
c.casttoarray r
call c.casttoarray(r)
或强烈输入casttoarray
参数。