以下代碼有效。連接打開正常,但recordset.recordCount始終在表中有數據時返回-1。如果我嘗試調用記錄集上的任何方法/屬性,它會崩潰Excel。有任何想法嗎?? 感謝使用Excel從Excel連接到Oracle 10g VBA
Sub GetData()
Dim conn As New ADODB.connection
Dim connString
connString = "DSN=name;Uid=user;Pwd=pass"
Dim rsRecords As New ADODB.recordSet
conn.Open connString
rsRecords.CursorLocation = adUseServer
rsRecords.Open "select * from xxx", conn, adOpenForwardOnly, adLockReadOnly
If conn.State = adStateOpen Then
MsgBox rsRecords.RecordCount
Else
MsgBox "no connection"
End If
rsRecords.Close
Set rsRecords = Nothing
conn.Close
Set conn = Nothing
End Sub