Merging Datasets and Getting Changed RRS feed

  • Question

  • I have created 2 datasets one from Access and one in CE. They have, I think, I identical schemas.

    The Access will normally have more. I am trying to merge them so I can sync the CE dataset with the Access dataset which is the "master". When I do my merge the two are identical which is correct but when I get the the changes the ones that show as changed are the "old one" that already there.

    There are 4 rows in the Access but 3 in the CE. When I merge there are 4 in both but the changes show up 3 that were already there not the newly added one. Hope that make sense.



          string SageQuery = "SELECT STOCK_CODE AS StockCode, DESCRIPTION AS StockDescription,PURCHASE_REF As SupplierRef,SALES_PRICE As StockPrice FROM STOCK";
          OleDbConnection SageConn = new OleDbConnection(GetAccessConnString());
          var DSSage = new DataSet();
          var DSCE = new DataSet();
          var DSMerged = new DataSet();
          OleDbDataAdapter SageAdapter = new OleDbDataAdapter(SageQuery, GetAccessConnString());
          SageAdapter.Fill(DSSage, "DS");
          SqlCeConnection CEConn = null;
          string CESelectQuery = "SELECT StockCode, StockDescription,SupplierRef,StockPrice FROM STOCK";
          CEConn = new SqlCeConnection(GetCEConnString());
          SqlCeDataAdapter CEAdapter = new SqlCeDataAdapter(CESelectQuery, CEConn);
          CEAdapter.AcceptChangesDuringFill = false;
          CEAdapter.Fill(DSCE, "DS");
          DataColumn[] pk = new DataColumn[1];
          pk[0] = DSSage.Tables[0].Columns["StockCode"];
          DSSage.Tables[0].PrimaryKey = pk;
          DataColumn[] pkCE = new DataColumn[1];
          pkCE[0] = DSCE.Tables[0].Columns["StockCode"];
          DSCE.Tables[0].PrimaryKey = pkCE;    
          DSMerged = DSCE.GetChanges();

    Thursday, March 10, 2011 7:28 PM


All replies