none
If I want to add another 10 columns in table orders, how to change code or store procedures? (in sync step) RRS feed

Answers

  • using the sample scripts from what you have downloaded:

    -- S-proc's for orders table
    create procedure dbo.sp_orders_applyinsert (
            @sync_last_received_anchor binary(8) , 
            @sync_row_count int out,
            @order_id int = NULL ,
            @order_date datetime = NULL)        
    as
    	insert into [orders] ([order_id], [order_date]) 
    		values (@order_id, @order_date)
    	if @@rowcount = 1
    		--once you apply insert from server, set your originator id to be servers
    		update [orders] set update_originator_id = 1 where [order_id] = @order_id
    	set @sync_row_count = @@rowcount
    go
    
    --change to 
    
    create procedure dbo.sp_orders_applyinsert (
            @sync_last_received_anchor binary(8) , 
            @sync_row_count int out,
            @order_id int = NULL ,
            @order_date datetime = NULL,
            @columnA vachar(10),
            @columnB int)        
    as
    	insert into [orders] ([order_id], [order_date],columndA, ColumnB) 
    		values (@order_id, @order_date, @columnA, columnB)
    	if @@rowcount = 1
    		--once you apply insert from server, set your originator id to be servers
    		update [orders] set update_originator_id = 1 where [order_id] = @order_id
    	set @sync_row_count = @@rowcount
    go

    then on code

    // insert row com
    SqlCommand insOrdersCmd = new SqlCommand();
    insOrdersCmd.CommandType = CommandType.StoredProcedure;
    insOrdersCmd.CommandText = "sp_orders_applyinsert";
    insOrdersCmd.Parameters.Add("@order_id", SqlDbType.Int);
    insOrdersCmd.Parameters.Add("@order_date", SqlDbType.DateTime);
    insOrdersCmd.Parameters.Add("@" + SyncSession.SyncClientIdHash, SqlDbType.Int);
    insOrdersCmd.Parameters.Add("@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Binary, 8);
    insOrdersCmd.Parameters.Add("@" + SyncSession.SyncRowCount, SqlDbType.Int).Direction = ParameterDirection.Output;
    
    adapterOrders.InsertCommand = insOrdersCmd;
    
    
    //change to
    
    // insert row com
    SqlCommand insOrdersCmd = new SqlCommand();
    insOrdersCmd.CommandType = CommandType.StoredProcedure;
    insOrdersCmd.CommandText = "sp_orders_applyinsert";
    insOrdersCmd.Parameters.Add("@order_id", SqlDbType.Int);
    insOrdersCmd.Parameters.Add("@order_date", SqlDbType.DateTime);
    insOrdersCmd.Parameters.Add("@ColumnA", SqlDbType.VarChar,10);
    insOrdersCmd.Parameters.Add("@ColumnB", SqlDbType.Int);
    insOrdersCmd.Parameters.Add("@" + SyncSession.SyncClientIdHash, SqlDbType.Int);
    insOrdersCmd.Parameters.Add("@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Binary, 8);
    insOrdersCmd.Parameters.Add("@" + SyncSession.SyncRowCount, SqlDbType.Int).Direction = ParameterDirection.Output;
    
    adapterOrders.InsertCommand = insOrdersCmd;

     you would do the same for the SelectIncremental SPs and the code as well as for the Update command, the triggers, etc...

    Wednesday, March 31, 2010 10:21 PM
    Moderator