CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2002
    Posts
    90

    Copy ms access tables from one table to an other using vb.net

    Hi everyone,
    I need to know how to copy a ms access table from database A to database B using vb.net. What classes of the OLEDB namespaces will allow me to do this?
    Thanks for your help.

  2. #2
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Copy ms access tables from one table to an other using vb.net

    You could execute a query to insert all the records to a new table.
    Code:
    SELECT Table1.* INTO Table2 FROM Table1;
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Copy ms access tables from one table to an other using vb.net

    Quote Originally Posted by mpoincare
    Hi everyone,
    I need to know how to copy a ms access table from database A to database B using vb.net. What classes of the OLEDB namespaces will allow me to do this?
    Thanks for your help.
    How about using a simple query to do this, instead of using any of the classes.

    a simple query to copy a Table from one MDB file to Another MDB File will look like this
    Code:
    SELECT Table1.* INTO TABLE1 IN 'C:\test.mdb' FROM Table1;
    You will have to run this query using the OleDBCommand Object.

    First open a connection to the database from which you want to copy the table, then execute the above mentioned query(Change it to suit your needs). Give the path of the new DB where you want your table to be copied..

    PS: This query will always drop the table if it exists in the Target DB.

  4. #4
    Join Date
    Aug 2005
    Posts
    2

    Re: Copy ms access tables from one table to an other using vb.net

    Hi,

    Do you by any chance know how to do this if the source db is SQL Server instead of Access.

    I tried with access and it worked fine, even though the target table had to be droppet before copied..

    I tried with SQL Server as source db both using SQL and OleDb but I didn't get it to work.

    Any tips?

    Regards

    Jonni

  5. #5
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Copy ms access tables from one table to an other using vb.net

    SQL Server syntax should be the same

    I use this every day

    SELECT * into tablename1 from tablename2

    will copy table2 into table1
    Nicolas Bohemier

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Copy ms access tables from one table to an other using vb.net

    [ Merged threads ]

  7. #7
    Join Date
    Aug 2005
    Posts
    2

    Re: Copy ms access tables from one table to an other using vb.net

    Maybe I was unclear, I don't want the target db to be SQL Server only the source db. I want to copy a SQL Server table to an access db, so I guess I have to tell to which db I want to copy the table to.

    For Access it's working this way:

    SELECT Table1.* INTO Table2 IN 'C:\LeLog\dbSync2.mdb' FROM Table1

    When I run this query to an access db it works fine but when I run it to SQL Server it get: Incorrect syntax near keyword 'IN', so I suppose the syntax is different to name the destination db in SQL Server..

    Any ideas?

    Regards

    Jonni

  8. #8
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Copy ms access tables from one table to an other using vb.net

    ok you want to copy a table from Access to SQL-Server and / or Copy a SQL server table to access..

    Well I think you may want to check on DTS...


    Because I don't think in access you can do

    SELECT * into Table1 from servername.databasename.owner.tablename

    In SQL server if you want to copy from server to server can either use DTS

    SELECT * into server.database.owner.tablename from server.database.owner.tablename
    Nicolas Bohemier

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