I am using the following code to select from one database and need to insert into another database.. Please suggest me the code:
Code :
'Connection for Original database from where i have to import
Dim constrOrg As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strPath
Dim conn_OrgDB As New OleDb.OleDbConnection(constrOrg)
'Connection for my database to where i have to import
Dim App_Path = System.AppDomain.CurrentDomain.BaseDirectory()
Dim constr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App_Path + "Mydb.accdb"
Dim cnnOLEDB As New OleDb.OleDbConnection(constr)
Dim strSelInv_one As String = ("SELECT * FROM INV_ONE where (DOCU_DT>=@stdt AND DOCU<=@enddt) ")
Dim comm_inv_one As OleDb.OleDbCommand = New OleDb.OleDbCommand(strSelInv_one, conn_OrgDB )
comm_inv_one.Parameters.AddWithValue("@stdt", StTime)
comm_inv_one.Parameters.AddWithValue("@enddt", Endtime)
dr = comm_inv_one.ExecuteReader
Do While dr.Read = True
Dim strInsInv1 As String = "INSERT INTO INVOICE_ONE(CODE_NO,LAY,..) SELECT CODE_NO,LAY,... FROM INV_ONE where (CODE_NO=@code)"
Dim comm_Insinv1 As OleDb.OleDbCommand = New OleDb.OleDbCommand(strInsInv1, cnnOLEDB)
comm_Insinv1.Parameters.AddWithValue("@code", Code_no)
comm_Insinv1.ExecuteNonQuery()
Loop
'Here INVOICE_ONE table belongs cnnOLEDB connection obj of one database and INV_ONE table belongs to conn_OrgDB connection object of another database..
' How to use the 2 connection object ? If i use only one connection object i.e. cnnOLEDB it gives the following Error:
" The Microsoft Office Access database engine cannot find the input table or query 'INV_ONE'. Make sure it exists and that its name is spelled correctly. "
Please suggest me the code.. Thank you