This is a migrated thread and some comments may be shown as answers.

Batch Updating only rows that have changed

1 Answer 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff Ehrenberg
Top achievements
Rank 2
Jeff Ehrenberg asked on 07 Apr 2010, 06:50 PM

I have a RadGrid that puts all rows in to editmode when the page loads, as outlined in the documentation using the PreRender event.  I have also configured an UpdateAll item command to enable updating all records at once, as outlined in "Performing Batch Updates".  The problem is that it updates all records even if no change was made.  Is there someway to mark a row as dirty and only run the update query if it has changed?
Any suggestions on how I can limit the update to only fire if a change to the row was made?

Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand  
        If e.CommandName = "UpdateAll" Then 
            For Each editedItem As GridEditableItem In RadGrid1.EditItems  
                Dim newValues As Hashtable = New Hashtable  
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)  
                sdsSODetails.UpdateCommand = String.Format("UPDATE rx_srorder_extend SET STOP_NO='{0}', PLAN_REC_DATE='{1}', CONF_REC_DATE='{2}', CONF_NO='{3}', CONF_BY='{4}', CHANGED_BY='{6}' WHERE SRORDER_ID='{7}' IF @@ROWCOUNT = 0 INSERT INTO rx_srorder_extend (SRORDER_ID, PLAN_REC_DATE, CONF_REC_DATE, CONF_NO, CONF_BY, STOP_NO, CHANGED_BY) VALUES ('{7}', '{1}','{2}','{3}','{4}','{0}','{6}')", newValues("STOP_NO"), newValues("PLAN_REC_DATE"), newValues("CONF_REC_DATE"), newValues("CONF_NO"), newValues("CONF_BY"), newValues("SCHED_STATUS_ID"), newValues("CHANGED_BY"), editedItem.GetDataKeyValue("SRORDER_ID").ToString())  
               sdsSODetails.Update()  
            Next 
        End If 
    End Sub 
 
    Private Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender  
        If Not IsPostBack Then 
            For Each item As GridItem In RadGrid1.MasterTableView.Items  
                If TypeOf item Is GridEditableItem Then 
                    Dim editableItem As GridEditableItem = CType(item, GridDataItem)  
                    editableItem.Edit = True 
                End If 
            Next 
            RadGrid1.Rebind()  
        End If 
    End Sub 
 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Apr 2010, 08:02 AM
Hi,

I have found a forum post which explains the batch updation of dirty rows. Hope this will work for you.

Regards
Princy
Tags
Grid
Asked by
Jeff Ehrenberg
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or