C# and inserting data from mdb file RRS feed

  • Question

  • I use the following code to insert data from a mdb file into another using the Merge() method of a DataSet...But it's not very effective in terms of performance. Is it possible to use a sql query to directly insert the data from a table in the second mdb file into the same table in the 1 first mdb file? I don't know how to create the code to link the databases..
    public void MergeTables(string connS1, string connS2)
    string connString1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS1;
    string connString2 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS2;
    OleDbConnection oleConn1 = new OleDbConnection(connString1);
    OleDbConnection oleConn2 = new OleDbConnection(connString2);
    string cmd1 = "SELECT *FROM db1_table1";
    string cmd2 = "SELECT *FROM db2_table1";
    OleDbDataAdapter da1 = new OleDbDataAdapter(cmd1, oleConn1);
    OleDbDataAdapter da2 = new OleDbDataAdapter(cmd2, oleConn2);
    DataSet ds1 = new DataSet();
    da1.Fill(ds1, "db1_table1");
    da2.Fill(ds1, "db2_table1");


    foreach (DataRow row in ds1.Tables["db1_table1"].Rows)

    OleDbCommandBuilder cmdBld = new OleDbCommandBuilder(da1);
    da1.UpdateCommand = cmdBld.GetUpdateCommand();
    @da1.Update(ds1, "db1_table1");

    I know that I have to use INSERT INTO SELECT statement but don't know how write the query using C# and SQL for the OleDbCommand.
    Sorry for my poor English 
    Friday, April 11, 2008 10:39 AM