C
Colin Svingen
Hello,
I have a DataTable with an autoincrement primary key that is retrieved
from the database after insert. The Primary key is returned with the
following code:
this.DataAdapter.InsertCommand.UpdatedRowSource =
UpdateRowSource.FirstReturnedRecord;
When I execute my InsertCommand within an SqlTransaction the rows in the
DataTable are updated with the autogenerated key from SQL Server.
However, when one of the inserts fail and I rollback the entire
transaction, all my DataRows are left with the invalid keys from the
database and a RowState of DataRowState.Unchanged instead of
DataRowState.Added.
So, when I rerun this code:
this.DataAdapter.Update(this.Table);
nothing happens. No inserts are performed. This kind of defeats the
purpose of having an SqlTransaction. No changes are made to the
database, but permanent changes are made to the DataTable. Is this a
bug? A feature? Can anyone help me with a workaround?
Colin Svingen
I have a DataTable with an autoincrement primary key that is retrieved
from the database after insert. The Primary key is returned with the
following code:
this.DataAdapter.InsertCommand.UpdatedRowSource =
UpdateRowSource.FirstReturnedRecord;
When I execute my InsertCommand within an SqlTransaction the rows in the
DataTable are updated with the autogenerated key from SQL Server.
However, when one of the inserts fail and I rollback the entire
transaction, all my DataRows are left with the invalid keys from the
database and a RowState of DataRowState.Unchanged instead of
DataRowState.Added.
So, when I rerun this code:
this.DataAdapter.Update(this.Table);
nothing happens. No inserts are performed. This kind of defeats the
purpose of having an SqlTransaction. No changes are made to the
database, but permanent changes are made to the DataTable. Is this a
bug? A feature? Can anyone help me with a workaround?
Colin Svingen