Guys, I need some help.
I have a sample vba script which successfully gets data from oracle and places it into excel.
What I want to do is take information from excel sheet and insert into oracle
here is the script but please note I have just used static values but the idea is to use data from an excel sheet
Sub Insert_Oracle()
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Dim source As String
Dim user As String
Dim password As String
Dim rg As Range
Source = Login.TextBox1.Value
user = Login.TextBox2.Value
password = Login.TextBox3.Value
' open the database
Set cn = New ADODB.Connection
cn.Open "Provider=OraOLEDB.Oracle;" & _
"Data Source=" & Source & ";" & _
"User Id=" & user & ";" & _
"Password=" & password & ""
Set rs = New ADODB.Recordset
With rs
' open the recordset
' sSQL = "SELECT p.PROJECT_ID, p.SUB_PROJECT_ID, p.ACTIVITY_NO, p.ACTIVITY_SEQ, p.DESCRIPTION, p.PROJECT_ID||p.ACTIVITY_NO as ID " & _
' "FROM IFSAPP.PROJECT_ACTIVITY_ALL p WHERE (p.SUB_PROJECT_ID='50') "
sSQL = "INSERT INTO IFSAPP.TESTTEST (OBJECT_ID, WO_NO, SITE, CRAFT, CRAFT_RATE, QTY_HOURS, AMOUNT, DAY, OBJID)" & _
"values ( 10007, 11111, 'B0101', 'PAINT100', 99, 10, 1000, 12/03/2015, SYSDATE); "
rs.Open sSQL, cn, adOpenStatic, adLockReadOnly, adCmdText
For intColIndex = 0 To rs.Fields.Count - 1 ' the field names
TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
Next
TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset data
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Can someone please modify this so that I can insert records from SHEET1 in excel into a table called TESTTEST.
Your help is very much appreciated
More can be found with the help of Dr. Google :-))
When you want to perform DMLs using ADODB, you'll have to work with transactions explicitly, e.g.:
Open in new window