none
Cannot sync new rows only RRS feed

  • Question

  • Hi,

     

    Is there any way of skipping Updates on existing rows and only make the Inserts?

     

    When I make a download of Master Tables from Server to Client, it's alright to download and update everything, buy when I come back from Client to Server, if they made any change on an existing row, I don't want to update it, only upload new rows.

     

    Please If need more detailed information, let me know, thanks in advance.

     

    Ramiro

    Friday, October 8, 2010 2:35 PM

Answers

  • Excellent workaround, it work perfectly with some slight modifications, I'll copy my code here as an example...

     

    //Fist we have to attach our function to the Handler
    ((SqlSyncProvider)syncOrchestrator.LocalProvider).ChangesSelected += new EventHandler<DbChangesSelectedEventArgs>(ServerSyncProvider_ChangesSelected);
    
    static void ServerSyncProvider_ChangesSelected(object sender, Microsoft.Synchronization.Data.DbChangesSelectedEventArgs e)
    {
      //We look for every table in the scope
      for (int i = 0; i < e.Context.DataSet.Tables.Count; i++)
      {
        var dataTable = e.Context.DataSet.Tables[i];
        for (int j = 0; j < dataTable.Rows.Count; j++)
        {
          DataRow row = dataTable.Rows[j];
          if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Deleted)
          {
            //If we are updating or deleting, we remove the row.
            dataTable.Rows.Remove(dataTable.Rows[j]);
          }
        }
      }
    
    }
    

    Thanks!

    Ramiro

    • Marked as answer by Ramiro R Monday, October 11, 2010 2:50 AM
    Friday, October 8, 2010 9:01 PM

All replies

  • which providers are you using? if its the offline providers, you can take out the SelectincrementalUpdate and SelectIncrementalDelete.
    Friday, October 8, 2010 3:48 PM
    Moderator
  • which providers are you using? if its the offline providers, you can take out the SelectincrementalUpdate and SelectIncrementalDelete.
    I'm using SqlSyncProvider, both Server and Client are SQL Server 2005. Can you give me any kind of information about SelectincrementalUpdate and SelectIncrementalDelete? I'm not being able to find any reference to that...
    Friday, October 8, 2010 5:31 PM
  • the SelectIncremental properties are in the offline providers.

    SQLSyncProvider doesnt allow you to selectively specify either Insert, Update or Delete only operations.

    please chk this thread for a similar workaround: http://social.microsoft.com/Forums/en-US/syncdevdiscussions/thread/fbc354b7-6b5e-43f7-9560-e1d86477b161

    basically, what you need to do is to intercept the changes on the client side, loop thru the dataset, check the rowstate and remove rows that are tagged as updated or deleted. Make sure you use Remove rather than Delete. Remove takes out the row from the collection, Delete will flag the row as deleted and if it reaches the server, it will be applied as a delete.

    Friday, October 8, 2010 5:43 PM
    Moderator
  • Excellent workaround, it work perfectly with some slight modifications, I'll copy my code here as an example...

     

    //Fist we have to attach our function to the Handler
    ((SqlSyncProvider)syncOrchestrator.LocalProvider).ChangesSelected += new EventHandler<DbChangesSelectedEventArgs>(ServerSyncProvider_ChangesSelected);
    
    static void ServerSyncProvider_ChangesSelected(object sender, Microsoft.Synchronization.Data.DbChangesSelectedEventArgs e)
    {
      //We look for every table in the scope
      for (int i = 0; i < e.Context.DataSet.Tables.Count; i++)
      {
        var dataTable = e.Context.DataSet.Tables[i];
        for (int j = 0; j < dataTable.Rows.Count; j++)
        {
          DataRow row = dataTable.Rows[j];
          if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Deleted)
          {
            //If we are updating or deleting, we remove the row.
            dataTable.Rows.Remove(dataTable.Rows[j]);
          }
        }
      }
    
    }
    

    Thanks!

    Ramiro

    • Marked as answer by Ramiro R Monday, October 11, 2010 2:50 AM
    Friday, October 8, 2010 9:01 PM
  • Hi Ramiro,

     

              I am using Microsoft SQL Server 2008 R2 (RTM) and Microsoft SQL Server 2008 (SP1) for syncronisation,i want to display changes in datagridview(windows) before sync.Could u please send code snippet,this is very urgent.I tried the logic which u poseted,but its not working for me.

     

     

     

    Thanks!

    Jagadeesh

    Thursday, July 7, 2011 6:31 AM