Anthony Wieser
2010-05-14 09:40:43 UTC
I knocked up a very quick database editing program using C# 2008 express.
I had my database which has an integer autonumber ID, and a bunch of other
text fields.
I then built a simple form with a DataGridView, and a couple of stray edit
fields, that are bound to values of the selected row.
If I insert a new row, it gets inserted into the database, but if I then
click on another row, and back to the new one, I get a
System.Data.DBConcurrencyException which I suspect is caused by the ID of
the row not being updated in the data table.
My OnRowValidated handler of the form says:
if (this.libraryDataSet.HasChanges())
{
this.libraryTableAdapter.Update(libraryDataSet.Library);
}
I've seen code on the web that suggests refilling the table after an insert,
but that seems like overkill to reload the whole table.
I seen another that suggests setting the "Refresh the data table" option on
the TableAdapter configuration wizard, but that is disabled with SQL Server
CE 3.5 SP1
Any suggestions on the right way to do this seemingly simple task?
I had my database which has an integer autonumber ID, and a bunch of other
text fields.
I then built a simple form with a DataGridView, and a couple of stray edit
fields, that are bound to values of the selected row.
If I insert a new row, it gets inserted into the database, but if I then
click on another row, and back to the new one, I get a
System.Data.DBConcurrencyException which I suspect is caused by the ID of
the row not being updated in the data table.
My OnRowValidated handler of the form says:
if (this.libraryDataSet.HasChanges())
{
this.libraryTableAdapter.Update(libraryDataSet.Library);
}
I've seen code on the web that suggests refilling the table after an insert,
but that seems like overkill to reload the whole table.
I seen another that suggests setting the "Refresh the data table" option on
the TableAdapter configuration wizard, but that is disabled with SQL Server
CE 3.5 SP1
Any suggestions on the right way to do this seemingly simple task?
--
Anthony Wieser
Wieser Software Ltd
Anthony Wieser
Wieser Software Ltd