I am trying to create an event which will truncate the data on oracle db table "ded_limit_analysis" and insert from ms access table "Ded-Limit-Analysis" using ADODB connection.
So far I am able to set up the connection and able to excute the truncate query to oracle db table after doing lot research, see the below code. I am pretty much new in this stuff, so it will be great if someone help to achieve this one.
for your information, ms database name is Ded-Limit-ACCM.accdb and I have made both the tables column name as identical, please help...
Private Sub CheckCon()
Dim rs As New ADODB.Recordset
'Dim db As Database
' Dim cntr As Long
Dim con As New ADODB.Connection
Dim str As String
'con.Open ("Provider=PROVIDER;Data Source=SOURCE;User ID=USERID; Password=PASSWORD;")
str = "Provider=PROVIDER;Data Source=SOURCE;Persist Security Info=True;Password=PASSWORD;User ID=USERID"
'Set cnn = CreateObject(“ADODB.Connection”)
con.Open str
'Set rs = CreateObject(“ADODB.Recordset”)
If con.State = adStateOpen Then
MsgBox "Welcome to database!"
Else
MsgBox "Sorry. No database."
End If
strSQL = "truncate table ded_limit_analysis"
rs.Open strSQL, con
Do Until rs.EOF
MsgBox rs.Fields(0)
rs.MoveNext
Loop
End Sub
Adding the code I have done so far but not having any luck, I am not getting any error also, please see the below code.
Private Sub comInsert_Click()
Dim rs As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim strSQL As String
Dim str As String
Dim dbs As Database
Set dbs = OpenDatabase("C:\Users\cthoud01\Documents\Ded-Limit-ACCM.accdb")
str = "Provider=MSDAORA;Data Source=SOURCE;Persist Security Info=True;Password=PASSWORD;User ID=USERID"
con.Open str
If con.State = adStateOpen Then
MsgBox "Welcome to database!"
Else
MsgBox "Sorry. No database."
End If
strSQL = "Insert Into ded_limit_analysis (PDPD_ID,PDDS_DESC,PRODUCT_CAT,BASE_PDPD_ID,PROD_CYCLE,HMO_IND_DED,HMO_FAM_DED,HMO_DED_TO_OOP,HMO_IND_FAC_DED,HMO_FAM_FAC_DED,HMO_DED_PFX_RQD,INN_IND_DED,INN_FAM_DED,INN_DED_TO_OOP,OON_IND_DED,OON_FAM_DED,OON_DED_TO_OOP,INN_OON_DED_PFX_RQD,DED_CARRY_OVR,PLAN_TIER,INN_OON_DED_REL,HMO_IND_OOP,HMO_FAM_OOP,INN_IND_OOP,INN_FAM_OOP,OON_IND_OOP,OON_FAM_OOP,INN_OON_OOP_REL,RX_DED_AMT,RX_DED_TO_MED_DED,RX_DED_TO_OOP,LMT1_SERV,LMT1_TYPE,LMT1_VALUE,LMT1_NTWK,LMT2_SERV,LMT2_TYPE,LMT2_VALUE,LMT2_NTWK,LMT3_SERV,LMT3_TYPE,LMT3_VALUE,LMT3_NTWK,LMT4_SERV,LMT4_TYPE,LMT4_VALUE,LMT4_NTWK,LMT5_SERV,LMT5_TYPE,LMT5_VALUE,LMT5_NTWK,LMT6_SERV,LMT6_TYPE,LMT6_VALUE,LMT6_NTWK,LMT7_SERV,LMT7_TYPE,LMT7_VALUE,LMT7_NTWK,LMT8_SERV,LMT8_TYPE,LMT8_VALUE,LMT8_NTWK,HMO_LTLT_PFX_RQD,INN_LTLT_PFX_RQD,OON_LTLT_PFX_RQD) " _
& "select * " _
& "from [Ded-Limit-Analysis];"
con.Execute strSQL
con.Close
dbs.Close
End Sub
I have exactly same requirements as yours. I am providing my solution with comments but its in c#. you'll have to bundle all methods into one class , define any missing variables and invoke the class method ReadAndInsertIntoDB()and you are done.
You can run it from your visual studio or prepare the exe (Console application) suggested and execute from dos prompt. it will keep working in background.
I am assuming that column names and data types for source and destination tables are same or equivalent. I have setup all the variables through app.config file.
Get list of tables from destination db to be updated
Get List of tables from source db to read data
Extension Method to check column exist in destination table
This implementation is assuming that source and destination db has tables with same column name and equivalent data types.
To call this implementation after you created the class