Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2005
    Posts
    74

    Unanswered: Copy Table from one database to another

    Hi guys Help please! Say I have db1.mdb and db2.mdb and in db1.mdb I have a table named 'members' and i want to copy the table and the values to db2.mdb how will i do this programmatically. Thanks in advance!

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    I'd say just use a SELECT INTO query, and then just use the IN clause to get the table into another mdb.
    Me.Geek = True

  3. #3
    Join Date
    Sep 2005
    Posts
    74
    Is it somthing like this?

    Code:
                string conStrAccess = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=db1.mdb;Jet OLEDB:Database Password=mypassword";                        
                connection = new OleDbConnection(conStrAccess);
                command = new OleDbCommand("select into [members] in 'db2.mdb' select * from members");
                command.CommandType = CommandType.Text;
                command.Connection = connection;
                command.ExecuteNonQuery();
    but this produces an error

    The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

  4. #4
    Join Date
    May 2009
    Posts
    508
    Provided Answers: 1
    daimous, I am not sure but I think you problem is the last SELECT *.

    "select into [members] in 'db2.mdb' select * from members")

    Try:

    "select * into [members] in 'db2.mdb' from members"

    At least that looks more like the example Nick pointed to.

  5. #5
    Join Date
    May 2005
    Posts
    1,191
    Stealth is right on the correction. I'm not sure off the top of my head, but I think you may also need to include the full path of db2.mdb, that is

    "SELECT [members].* INTO [members] IN 'C:\db2.mdb' FROM [members]"
    Me.Geek = True

  6. #6
    Join Date
    Sep 2005
    Posts
    74
    Thanks! but there is a problem, i forgot to mention that db2.mdb and db1.mdb are password protected..so when i try the syntax above it produces an error something like password is incorrect..

  7. #7
    Join Date
    Sep 2005
    Posts
    74
    This Solved My Problem

    excerpt...
    ealcaniz,
    Thank you for your prompt answer.

    I found this solution which seems to solve my problem.
    http://www.experts-exchange.com/Micr...html#a22781336
    So, I modified my sql statement so that instead of
    SELECT * INTO newTable IN E:\Databases\myDb.mdb FROM sourceTable;
    now I am using
    SELECT * INTO newTable IN ' ' [;Database=E:\Databases\myDb.mdb;pwd=myPassword] FROM sourceTable;

    After IN there are two single quotes indicating a ZLS, what does that mean?

    I would be happy if you could help me with an explanation or guide me to a site where I could learn more about this syntax.

    Regards,
    Stellan
    Last edited by daimous; 05-28-09 at 23:09.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •