我试图让这段代码工作,但它一直为 RecordCount 返回 -1。select 语句确实找到了值,我去了数据库并在那里运行它。但我无法在我的程序中获得任何值。
Dim quotedPubs As ADODB.Connection
Set quotedPubs = New ADODB.Connection
quotedPubs.Open "PROVIDER=SQLOLEDB; DATA SOURCE=*****;INITIAL CATALOG=*****; User ID=****; Password=****"
Dim hoursPubs As ADODB.Connection
Set hoursPubs = New ADODB.Connection
hoursPubs.Open "PROVIDER=SQLOLEDB; DATA SOURCE=*****;INITIAL CATALOG=*****; User ID=****; Password=****"
Dim lsPubs As ADODB.Recordset
Set lsPubs = New ADODB.Recordset
With lsPubs
.ActiveConnection = quotedPubs
.Open "SELECT ProjectNumber FROM hours h"
' WHERE h.lead = " & sEmpNum & ""
If (lsPubs.RecordCount > 0) Then
arr = lsPubs.GetRows(lsPubs.RecordCount)
.Close