Articles in this section
Category / Section

How can I save changes made in the Grid into the database?

1 min read

 

When the user makes changes in the grid, like editing a row, deleting a row or adding a new row, these changes are immediately saved in the bound data set. There are two ways in which changes can be saved to the underlying database.

Option 1:

It is standard practice to include a Save button (or some other UI element) in the page which could be used by the user to confirm all the changes.And in the event handler for the Save button, you can call Update on the data adapter to force changes into the database:

C#

this.oleDbDataAdapter1.Update(this.dataSetCustomers1);

VB

Me.oleDbDataAdapter1.Update(Me.dataSetCustomers1)

Option 2:

If the changes need to be saved into the database as soon as the user is done editing a row, deleting a row or adding a new row, then you can listen to the following events and call Update on the data adapter, as shown:

C#

// This will be called when the user edits or adds a new row.

private void GridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)

{

if(e.Action == CurrentRecordAction.EndEditComplete)

{

this.oleDbDataAdapter1.Update(this.dataSetCustomers1);

}

}

// This will be called when the user deletes a row

private void GridGroupingControl1_BarButtonItemClicked(object source, Syncfusion.Web.UI.WebControls.Grid.Grouping.ButtonBarItemClickEventArgs e)

{

if(e.ButtonBarItem.ButtonBarItemType==ButtonBarItemType.DeleteRow)

 {

  {

   Record curRecord = this.GridGroupingControl1.Table.CurrentRecord;

   curRecord.Delete();

this.oleDbDataAdapter1.Update(this.dataSetCustomers1);

  }

  }

}

VB

' This will be called when the user edits or adds a new row.

Private Sub GridGroupingControl1_CurrentRecordContextChange(ByVal sender As Object, ByVal e As Syncfusion.Grouping.CurrentRecordContextChangeEventArgs)

If e.Action = CurrentRecordAction.EndEditComplete Then

Me.oleDbDataAdapter1.Update(Me.dataSetCustomers1)

End If

End Sub

' This will be called when the user deletes a row

Private Sub GridGroupingControl1_BarButtonItemClicked(ByVal source As Object, ByVal e As Syncfusion.Web.UI.WebControls.Grid.Grouping.ButtonBarItemClickEventArgs) Handles GridGroupingControl1.BarButtonItemClicked

      If e.ButtonBarItem.ButtonBarItemType = ButtonBarItemType.DeleteRow Then

        Dim curRecord As Record = Me.GridGroupingControl1.Table.CurrentRecord

curRecord.Delete()

Me.oleDbDataAdapter1.Update(Me.dataSetCustomers1)

      End If

End Sub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied