|
-
September 6th, 2001, 11:49 AM
#1
Urgent...Help needed
hi everyone,
i am working on inserting the records from one database to another database. The two access databases have exactly the same tables and fields. all that differs is the records in the table. i have a VB front end where the user can browse and find the source and destination .mdb files. i have to use VB ADO connection to open both the databases...then insert all the records from one database to the other.so if anyone know ADO commands for opening two databases please let me know...i shall b thankful...
luv n prayers,
sudhan
-
September 6th, 2001, 01:05 PM
#2
Re: Urgent...Help needed
' ---------------- Declaration
public dbConnection_m as Connection
public dbConnection2_m as Connection
public rsSQL_m as Recordset
Dim strSQL as string
' ---------------- Initialization
set dbConnection_m = new Connection
set dbConnection2_m = new Connection
'
set rsSQL_m = new Recordset
With rsSQL_m
.CursorType = adOpenForwardOnly
.CursorLocation = adUseServer
.LockType = adLockReadOnly
End With
' ---------------- Open source database
With dbConnection_m
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data source") = "C:\source.mdb"
.Open
End With
' ---------------- Open destinationdatabase
With dbConnection2_m
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data source") = "C:\destination.mdb"
.Open
End With
' ---------------- Read source database
strSQL = " SELECT field1,field2" & _
" FROM table" & _
" WHERE (field1=value)"
rsSQL_m.Open strSQL, dbConnection_m
' ---------------- Update destination database
While (Not rsSQL_m.EOF)
strSQL = " INSERT INTO table (field1,field2)" & _
" VALUES(" & Format(rsSQL_m!field1) & _
", " & Format(rsSQL_m!field2) & ")"
dbConnection2_m.Execute strSQL
rsSQL_m.NextRecordset
Wend
' ---------------- Close databases
dbConnection_m.Close
dbConnection2_m.Close
-
September 6th, 2001, 02:05 PM
#3
Re: Urgent...Help needed
INSERT INTO Table1 IN 'ExternalDatabasePath1' SELECT *
FROM Table1 IN 'ExternalDatabasePath2';
where externaldatabasepath1 & 2 are something like c:\databases\db1.mdb & c:\databases\db2.mdb
Example:
(INSERT INTO Table1 SELECT * FROM Table2 IN 'c:/aaa/bbb/Database.mdb' where ...)
Iouri Boutchkine
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|