0
我在oracle數據庫上運行SQL查詢,它只是一個簡單的select * from表查詢。這適用於小型表格900行和5列。但是當我在有30列和95,000行的表上嘗試時,我得到了下面的錯誤。我試圖增加MaxRecords,但無濟於事。在Excel VBA中運行SQL查詢時的運行時錯誤
Error 代碼
Public Const sConnect As String = "Driver={Microsoft ODBC for
Oracle};Server=server;Uid=user;Pwd=password"
Sub GetData1()
i = 0
Sheets(1).Range("a1:ao20000").ClearContents
Dim rsConnection As ADODB.Connection
Dim rsRecordset As ADODB.Recordset
Dim sQuery As String
sQuery = "select * from trade"
Set rsConnection = New ADODB.Connection
Set rsRecordset = New ADODB.Recordset
rsConnection.ConnectionString = sConnect
rsConnection.Open
rsRecordset.MaxRecords = 1048575
Set rsRecordset = rsConnection.Execute(sQuery)
Worksheets(1).Range("A2").CopyFromRecordset rsRecordset
For i = 0 To rsRecordset.Fields.Count - 1
Worksheets("Sheet1").Cells(1, i + 1).Value = rsRecordset.Fields(i).Name
Next i
rsConnection.Close
Set rsConnection = Nothing
Set rsRecordset = Nothing
End Sub
問候, 添