Use BindingManagerBase's EndCurrentEdit() before saving data via an Sql/OleDataAdapter - 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.
The LBTT Spot
"Lifeline is focused on developing and marketing systems designed to assist in the early detection of breast and ovarian cancer."



Use BindingManagerBase's EndCurrentEdit() before saving data via an Sql/OleDataAdapter

View C# Source Code

Article Categories:

.Net Framework
.Net Framework 1.1
ADO.NET
ASP.NET
Assemblies
Asynchronous Methods
C#
Collections
Configuration
Delegates
Events
Pocket PC
Regular Expressions
Smart Devices
SQL Server
Visual C#
Visual Studio .NET
Visual Studio .NET 2003
Windows Forms
XML

C# .Net Fun Menu

View Current Page's ASP.NET Source Code
C# Reference
C# Study Flash Cards
Valuable Links
Contact Us
Site Map
Mike's Portfolio

C# Reference Search:

Full Text Search:

Articles by Author:

Code Examples (zipped):

Use BindingManagerBase.EndCurrentEdit() before saving data via an Sql/OleDataAdapter

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.
Category: Windows Forms, Visual Studio .NET, Posted 1/5/2004, By Mike G.

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(); } }