Current .Net Version: 1.1.4322
Home
Articles
Practice C# Online
C# Reference
XML Web Services
RSS Feeds
T-SQL Scripts
Valuable Links
Contact Us
Use BindingManagerBase's EndCurrentEdit() before saving data via an Sql/OleDataAdapter
Author:Michael G.; Last Updated: 4/26/2005 3:46:07 PM
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