CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2001
    Posts
    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



  2. #2
    Join Date
    Aug 2000
    Location
    Ottawa, Canada
    Posts
    469

    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





  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    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]
    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
  •  





Click Here to Expand Forum to Full Width

Featured