Hello,

I've got a problem with my project... in short I've got a mysql db bond through a DataSet and BindingSource - if I'm editing like a user the gridview then all changes are commited to the db no problem...
But I need the user to responsibly change foreign keys - what I have done is: if the user doubleclicks on a foreign key cell a new form pops up with possible values, I can change the cell value to the new foreign ID by:

DataGridViewCell cell = dataGridView.CurrentCell;
cell.Value = (fk.getSelectedValue()).Value;

The grid refreshes and everything looks good but this change doesn't really go into the database... I've tried to modify the value through the DataSet but can't seem to get it right...

Any help on this one please? Or maybe somebody has a better idea how to change foreign keys?

Any suggestions appreciated.

To write back those changed data, you need to invoke Update method of dataAdapter. Showing your code might help.

To write back those changed data, you need to invoke Update method of dataAdapter. Showing your code might help.

This is the code I'm using to update the DB:

sqlAdapt.UpdateCommand = sqlCmd.GetUpdateCommand();
            sqlAdapt.DeleteCommand = sqlCmd.GetDeleteCommand();
            sqlAdapt.InsertCommand = sqlCmd.GetInsertCommand();
            sqlAdapt.Update(dset,tableName);

If I update the datagridview normally like a user then the changes commit to the db. But when I try to set a value of a cell through an other form

ForeignKey fk = new ForeignKey("BRANCHES", sql);
                        if (fk.ShowDialog() == DialogResult.OK)
                        { 
                            DataGridViewCell cell = dataGridView.CurrentCell;
                            
                            cell.Value = (fk.getSelectedValue()).Value;
                        }

then the value sets in the datagridview but then the update does not save it into the database... the gridview is bound to my bindingsource/dataset so I would think the changes should be flagged and update when called... but maybe I should try to change the dataset directly?

Any help on how to do it?

Thanks in advance

Any ideas anyone?

I'm changing the value of a cell through

dataGridView.CurrentCell.Value

but the change (visible on the datagrid) does not commit to the DB when changes inputed via keyboard do...

dataGridView.BeginEdit(true);
dataGridView.CurrentCell.Value = (fk.getSelectedValue()).Value;
dataGridView.EndEdit();
bind.EndEdit();
this.Validate();                            
dset.AcceptChanges();
dataGridView.Update();

After trying all of that it is still not commiting into the DB...

The column/row/cell is readOnly = false;

Help!
Please?

This article has been dead for over six months. Start a new discussion instead.