Sub ls()
Dim Rst As ADODB.Recordset
Dim Sql As String
Sql = "Select * From [Sheet1$]"
Set Rst = ConnectRst(Sql)
rr = Rst.GetRows(5, 2, Rst.Fields(0), Rst.Fields(1))
End Sub
Function ConnectRst(Sql As String) As ADODB.Recordset
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
Rst.Open Sql, Cnn, adOpenStatic
Set ConnectRst = Rst
End Function
上面程序
Rst.GetRows(5, 2, Rst.Fields(0), Rst.Fields(1))-有两个字段程序不通过
Rst.GetRows(5, 2, Rst.Fields(0))----有一个字段程序通过
问:在于vb GetRows的字段只能是一个字段吗?
Dim Rst As ADODB.Recordset
Dim Sql As String
Sql = "Select * From [Sheet1$]"
Set Rst = ConnectRst(Sql)
rr = Rst.GetRows(5, 2, Rst.Fields(0), Rst.Fields(1))
End Sub
Function ConnectRst(Sql As String) As ADODB.Recordset
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
Rst.Open Sql, Cnn, adOpenStatic
Set ConnectRst = Rst
End Function
上面程序
Rst.GetRows(5, 2, Rst.Fields(0), Rst.Fields(1))-有两个字段程序不通过
Rst.GetRows(5, 2, Rst.Fields(0))----有一个字段程序通过
问:在于vb GetRows的字段只能是一个字段吗?
for i 1 to 5
rr = Rst.GetRows(5, i+1, Rst.Fields(i))
next
http://msdn.microsoft.com/en-us/library/ms675120(VS.85).aspx
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
Fields
Optional. A Variant that represents a single field name or ordinal position, or an array of field names or ordinal position numbers. ADO returns only the data in these fields.an array of field names ,一个数组字段如何写,需要消化理解(Understanding of the need to digest)