Synchronizing two Access tables on remote databases from C# code RRS feed

  • Question

  • Hey,

    I have a C# problem I need to synchronize two MS Access tables from two different databases(two databases over a network) which is quite similar, I thought of using two different OleDbConnections and two DataAdapters to fill a Single DataSet and then manipulate the data in the DataSet, I think the source table (database with the primary data) should be loaded first (into the DataSet) then the secondary table from the remote database should subtract the existing records in the DataSet to get the difference then the difference should be Appended to the remote table, but I don’t know how to code this can you guys please help me?

    Here is some code I already have, but I don’t know how to get this to work:

    private void btn_update_Click(object sender, EventArgs e)
        private void UpdateExperiment()
          OleDbConnection connSource = new OleDbConnection();
          OleDbConnection connDest = new OleDbConnection();
          OleDbDataAdapter daSource = new OleDbDataAdapter();
          OleDbDataAdapter daDest = new OleDbDataAdapter();
          OleDbCommand commSource = new OleDbCommand();
          OleDbCommand commDest = new OleDbCommand();
          DataSet dsMutual = new DataSet();
          string strConnectionSource = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\db\\db1.accdb;Persist Security Info=False;"; //source db
          string strConnectionDestination = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\db\\db2.accdb;Persist Security Info=False;"; //destination db
          connSource.ConnectionString = strConnectionSource;
          connDest.ConnectionString = strConnectionDestination;
            commSource.Connection = connSource;
            commSource.CommandType = CommandType.Text;
            commSource.CommandText = "SELECT Catelog.[Col1], Catelog.[Col2], Catelog.[Col3], Catelog.[Col4] FROM Catelog";
            daSource.SelectCommand = commSource;
            //help here
          catch (Exception excException)
            MessageBox.Show(excException.Message, excException.Source, MessageBoxButtons.OK, MessageBoxIcon.Stop);

    Wednesday, September 29, 2010 12:30 PM