locked
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();
    
          SageConn.Open();
          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;    
          
          DSCE.Merge(DSSage);
          DSMerged = DSCE.GetChanges();
    

    Chris
    Thursday, March 10, 2011 7:28 PM

Answers

All replies

  • Hi Chris,

    Welcome!

    GetChanges() method gets a copy of the DataSet that contains all changes made to it since it was loaded or since AcceptChanges was last called.

    I think you should use GetChanges(DataViewState) , you can refer here: http://msdn.microsoft.com/en-us/library/system.data.dataset.getchanges.aspx

    Have a nice weekend.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Alan_chen Monday, March 21, 2011 1:58 AM
    • Marked as answer by Alan_chen Thursday, March 24, 2011 1:16 AM
    Friday, March 11, 2011 2:51 PM
  • Hi Chris,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 
     
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 21, 2011 1:58 AM
  • I went for a different approach in the end using linq to datasets to compare the two. It seem it is a popular misconception that the changes are set in the dataset after the merge.
    Chris
    • Marked as answer by Alan_chen Thursday, March 24, 2011 1:16 AM
    Wednesday, March 23, 2011 5:32 PM