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.
Unfortunately, activation email could not send to your email. Please try again.

Database only updates if choose a diffrent row

Thread ID:

Created:

Updated:

Platform:

Replies:

1090 Sep 20,2002 02:05 AM Oct 24,2002 01:35 AM Windows Forms 4
loading
Tags: FAQ
Brocky
Asked On September 20, 2002 02:05 AM

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 02:59 AM

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

Brocky
Replied On September 23, 2002 02:03 AM

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 03:41 AM

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 01:35 AM

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

CONFIRMATION

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.

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.

;