Exporting data from Excel to Oracle DB

Parth13

Board Regular
Joined
Dec 24, 2008
Messages
65
Hi,
I am trying to export data from excel sheet to a table on a oracle database but couldn't get the code below to work
It keeps throwing error at 2nd strSQL line. I seek help from forum to get this to work. thanks.

VBA Code:
Sub ExportXLtoOracle()


Dim con As ADODB.Connection
Dim conStr As String

Dim r As Long, c As Long, rMax As Long
Dim strSQL As String
Dim ws1 As Excel.Worksheet
Set ws1 = ThisWorkbook.Worksheets("Team")
Dim ExpRange As Range
Set ExpRange = ws1.Range("A2:D6")
conStr = "Provider=OraOLEDB.Oracle.1;Password=1234;Persist Security Info=True;User ID=ABCDE;Data Source=EMD21"

Set con = New ADODB.Connection
con.Open conStr

For lngRow = 1 To 10
        strSQL = "Insert Into ABCDE.DATA_TEMP" '/
        strSQL = strSQL & "'" & Range(ExpRange, 1).Value & "', "  '/ JAVA
        strSQL = strSQL & "'" & Range(ExpRange, 2).Value & "', "  '/ ORACLE
        strSQL = strSQL & "'" & Range(ExpRange, 3).Value & "', "   '/ C++
        strSQL = strSQL & "'" & Range(ExpRange, 4).Value & "' "    '/ C#
        con.Execute strSQL
    Next
    con.Close
    Set con = Nothing
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top