Hello There,
I have the below code which gets the data from a PL/SQL procedure in a ADODB.recordset and transfers the same into a table.
I would like to know how this could be done in a reverse way i.e. transfer the range table data to a ADODB.recordset (without looping through the entire range table).
Could you please advice?
Thanks & regards
Don
I have the below code which gets the data from a PL/SQL procedure in a ADODB.recordset and transfers the same into a table.
I would like to know how this could be done in a reverse way i.e. transfer the range table data to a ADODB.recordset (without looping through the entire range table).
Could you please advice?
Thanks & regards
Don
Code:
Sub GetData()
Dim cmd As New ADODB.Command
Dim RecordSet As New ADODB.RecordSet
Dim ExcelRange As Range
Dim param1 As New ADODB.Parameter
Dim param2 As New ADODB.Parameter
Dim objErr As ADODB.Error
'Connect to Oracle Database
OracleConnect
Set cmd.ActiveConnection = con
'Set Input parameters
DeptValue = 30
'Set parameters
With cmd.Parameters
.Append cmd.CreateParameter("param1", adSmallInt, adParamInput, 10, DeptValue)
.Append cmd.CreateParameter("param2", adSmallInt, adParamOutput)
End With
'Enable PLSQLRSet property
cmd.Properties("PLSQLRSet") = True
'PL/SQl ref cursor is pl/sql recordset, which is not displayed in the parameter
' but the provider auto fetches it in RecordSet
cmd.CommandText = "{CALL Employees.GetEmpRecords(?, ?)}"
Set RecordSet = cmd.Execute
'Disable PLSQLRSet property
cmd.Properties("PLSQLRSet") = False
'Set ws = ActiveWorkbook.Sheets("Sheet1")
Set ExcelRange = ws1.Range("E11")
'------------------------------------------------
'Copy PL/SQL recordset array into excel range
ExcelRange.CopyFromRecordset RecordSet
'------------------------------------------------
'Close connection to Oracle Database and Recordset
If RecordSet.State = adStateOpen Then RecordSet.Close
OracleDisConnect
End Sub