We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Database only updates if choose a diffrent row

Thread ID:





1090 Sep 20,2002 06:05 AM UTC Oct 24,2002 05:35 AM UTC WinForms 4
Tags: FAQ
Asked On September 20, 2002 06:05 AM UTC

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 SQLDataGridataGrid { 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); } } } } }

Clay Burch [Syncfusion]
Replied On 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);

Replied On 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.

Clay Burch [Syncfusion]
Replied On 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();

Administrator [Syncfusion]
Replied On 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!!


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon