Current .Net Version: 2.0.50727
Home
Articles
C# & .Net Framework Reference
Practice C# Online
XML Web Services
RSS Feeds
Code Snippets
T-SQL Scripts
Videos
Valuable Links
Contact Us
Mike's C#, VS.NET and SQL Blog




ROR XML Info.
Use BindingManagerBase's EndCurrentEdit() before saving data via an Sql/OleDataAdapter
Author: Michael G.     Last Updated:2/15/2004 12:00:00 AM
Category(ies): Windows Forms All
Description: If you are binding a Windows Forms DataGrid to a DataSet and updating it via an Sql/OleDataAdapter, you may want to use the form's BindingManagerBase.EndCurrentEdit() before calling the Adapter's Update() method.
  Add & View Comments About this Article

When a user places a cursor on a DataGrid cell in order to edit its contents, the grid is placed into an Edit mode state. If the user later clicks on a save button to commit the changes to a database, the changes may not be saved. This occurs because the DataGrid is still in Edit mode. For this reason, I recommend to all developers that the form, on which the DataGrid resides, be used to end the Edit mode session of the DataGrid. You can do this by issuing it a BindingManagerBase.EndCurrentEdit() before saving the data as follows: private void SaveMethod() { // This will end any opened edit mode sessions on the DataGrid: this.BindingContext[this.dgMyDataGrid.DataSource].EndCurrentEdit(); // Now we can save the changes via an Adapter update: if (dsMyDataSet.GetChanges() != null) { sqlAdapter.Update(dsMyDataSet.GetChanges()); dsMyDataSet.AcceptChanges(); } }

Comments Click Here to Add your Comment
No Comments Found.
 
COPYRIGHT/DISCLAIMER | CONTACT US