Database only updates if choose a diffrent row

Database only updates if choose a diffrent row, I have a datagrid wich is bound to a dataset. If change now something in the grid an call the dataadapter to update the database with the dataset it only updates it if i selected a other row in the datagrid. It also works ok if i select a diffrent control in my from and than call the update function. Any ideas how i can do this programmatical? I tried using i.e. listbox1.Select(), before i call the update Well that works optical but somehow its diffrent because ths databse still does not update only if i slect the other control or row by hand. thanks in advance here a Code snippet of my datagrid class and jow i call the update PHP:-------------------------------------------------------------------------------- void OnMenuSaveClick(object obj, EventArgs ea) { listBox1.Select(); listBox1.AddLog("Es wurde auf Speichern gedrückt"); dataGrid1.SaveCurrentGrid(); } using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; namespace ATGParaTool { /// /// Zusammendfassende Beschreibung für SQLDataGrid. /// public class SQLDataGrid { DataSet dataSet = null; OleDbConnection connection; OleDbDataAdapter dataAdapter; OleDbCommandBuilder custCB; string strTabel; public SQLDataGrid() { } public void RefreshSQL(string strCaption, string strConnectString, string strSQLString) { connection = new OleDbConnection(strConnectString); dataAdapter = new OleDbDataAdapter(strSQLString, connection); custCB = new OleDbCommandBuilder(dataAdapter); dataSet = new DataSet(); DataGridTableStyle dgts = new DataGridTableStyle(); strTabel = strCaption; dataSet.Clear(); dataAdapter.Fill(dataSet, strCaption); CaptionText = strCaption; DataSource = dataSet.Tables[strCaption].DefaultView; dgts.MappingName = strCaption; dgts.BackColor = Color.Beige; dgts.AlternatingBackColor = Color.AliceBlue; TableStyles.Clear(); TableStyles.Add(dgts); #region Die Weite der Spalten anpassen for(int col=0; col < dataSet.Tables[strCaption].Columns.Count; col++) { float width = 0; int numRows = dataSet.Tables[strCaption].Rows.Count; Graphics g = Graphics.FromHwnd(this.Handle); StringFormat sf = new StringFormat(StringFormat.GenericTypographic); SizeF size; for(int i = 0; i < numRows; ++ i) { size = g.MeasureString(this[i, col].ToString(), this.Font, 500, sf); if(size.Width > width) width = size.Width + 15; } g.Dispose(); this.TableStyles[strCaption].GridColumnStyles[col].Width = (int) width; } #endregion CurrencyManager cm = (CurrencyManager)this.BindingContext[DataSource, DataMember]; ((DataView)cm.List).AllowNew = false; } public void SaveCurrentGrid() { if(dataSet != null) { if(dataSet.Tables[strTabel].Rows.Count > 0) { dataAdapter.Update(dataSet, strTabel); } } } } }

4 Replies

CB Clay Burch Syncfusion Team September 21, 2002 06:59 AM UTC

Before calling the dataset Update method, try calling AcceptChanges on your datatable. dataSet.Tables[strTabel].AcceptChanges(); dataAdapter.Update(dataSet, strTabel);


BR Brocky September 23, 2002 06:03 AM UTC

I tryed it but it did not work only if i change into a diffrent row or if i set the focus on a diffrent control by hand the dataset takes the changes. Its almost the same if you work with access, thier it only accepts the changes if u move to a other cell. But here it only works if i go to another row.


CB Clay Burch Syncfusion Team September 23, 2002 07:41 AM UTC

Before calling the update, try CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dataGrid2.DataSource]; cm.Refresh(); If that does not work, you could also try calling cm.EndCurrentEdit();


AD Administrator Syncfusion Team October 24, 2002 05:35 AM UTC

CurrencyManager cm = (CurrencyManager)this.BindingContext[this.DataSource]; cm.EndCurrentEdit(); dataAdapter.Update(dataSet, strTable); EndCurrentEdit was the solution thank you!!

Loader.
Up arrow icon