Thanks for thinking with me guys. I tried but doesn't help. It gets in a neverending loop when the action commit is triggered. If i filter on that the error still comes up.
I added some debuging lines to track the whole process, maybe it helps. This is the sourcecode of the events to track what is happening.
void dataAdapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e)
{
System.Diagnostics.Debug.Print("### UPDATED("+ e.RecordsAffected + ") ###: " + e.Command.CommandText + " (" + e.Command.Parameters[0].Value + ")");
}
void dataAdapter_RowUpdating(object sender, OleDbRowUpdatingEventArgs e)
{
System.Diagnostics.Debug.Print("### UPDATING ###: " + e.Command.CommandText + " (" + e.Command.Parameters[0].Value + ")");
}
/************************************
* Makes sure that the database is updated after a row is deleted
***********************************/
void DatabaseTable_RowDeleted(object sender, DataRowChangeEventArgs e)
{
System.Diagnostics.Debug.Print("(" + this.table + ") Row Deleted: " + e.Action.ToString());
try
{
dataAdapter.Update(this);
this.AcceptChanges();
}
catch (OleDbException ex) {
System.Windows.Forms.MessageBox.Show(ex.Message);
}
catch (DBConcurrencyException ex) {
System.Diagnostics.Debug.Print("### ERROR ###: " + ex.Message);
}
}
/************************************
* Makes sure that the database is updated after a row is changed
***********************************/
void DatabaseTable_RowChanged(object sender, DataRowChangeEventArgs e)
{
System.Diagnostics.Debug.Print("(" + this.table + ") Row Changed: " + e.Action.ToString());
//if (e.Action == DataRowAction.Add || e.Action == DataRowAction.Change)
{
//System.Diagnostics.Debug.Print("(" + this.table + ") Row Changed: " + e.Row.ItemArray[0].ToString() + "-" + e.Row.ItemArray[1].ToString());
try
{
dataAdapter.Update(this);
if (e.Action != DataRowAction.Commit) this.AcceptChanges();
}
catch (OleDbException ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
The debug output when the deletion is succesfull
() Row Changed: Add
### UPDATING ###: INSERT INTO tbl_dagen (dag) VALUES (?) (sdfasd)
() Row Changed: Commit
### UPDATED(1) ###: INSERT INTO tbl_dagen (dag) VALUES (?) (sdfasd)
() Row Deleted: Delete
### UPDATING ###: DELETE FROM tbl_dagen WHERE id = ? (64)
### UPDATED(1) ###: DELETE FROM tbl_dagen WHERE id = ? (64)
() Row Changed: Commit
The output with the error
() Row Changed: Add
### UPDATING ###: INSERT INTO tbl_dagen (dag) VALUES (?) (sdfa)
() Row Changed: Commit
### UPDATED(1) ###: INSERT INTO tbl_dagen (dag) VALUES (?) (sdfa)
() Row Deleted: Delete
### UPDATING ###: DELETE FROM tbl_dagen WHERE id = ? (66)
### UPDATED(0) ###: DELETE FROM tbl_dagen WHERE id = ? (66)
A first chance exception of type 'System.Data.DBConcurrencyException' occurred in System.Data.dll
### ERROR ###: Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.
Thanks alot for helping, it really got me puzzled. I reckon it has something to do with how the ADO.NET functions in the background.
Thanks,
ChoKamir