Primary Keys and DB Triggers

  • Thread starter Thread starter zobie
  • Start date Start date
Z

zobie

I am using SQL Server 2000, VS.net 2003, C#.

In my application, when adding a row to a dataset, a primary key is
autogenerated. When I call dataadapter.Update (dataset.datatable); the
primary key is updated to match what was assigned in the database. This
works exactly as expected UNLESS there is a database trigger on the table
which is being updated. If there is a trigger on the database, the primary
key is NOT updated. If I call dataadapter.fill (dataset.datatable) again,
then I have two rows containing the same data with different primary keys.

This is a *huge* problem for me that I have not been able to overcome. Has
anyone else experienced this? Is there a solution?

Thanks,
Nate
 
zobie said:
I am using SQL Server 2000, VS.net 2003, C#.

In my application, when adding a row to a dataset, a primary key is
autogenerated. When I call dataadapter.Update (dataset.datatable); the
primary key is updated to match what was assigned in the database. This
works exactly as expected UNLESS there is a database trigger on the table
which is being updated. If there is a trigger on the database, the primary
key is NOT updated. If I call dataadapter.fill (dataset.datatable) again,
then I have two rows containing the same data with different primary keys.

This is a *huge* problem for me that I have not been able to overcome. Has
anyone else experienced this? Is there a solution?

Try using scope_identity(), instead of @@identity to return the key of the
new rows.

David
 
Thanks for the suggestion, but scope_identity() didn't make any difference.
The row is still not updated properly.

Nate
 
zobie said:
Thanks for the suggestion, but scope_identity() didn't make any difference.
The row is still not updated properly.

Nate

Post a test case to reproduce the issue.

David
 
Back
Top