Bill
Bill

Reputation: 3823

Retrieving the new ID from a SQLDataAdaptor.Update

How would you go about retrieving the @@IDENTITY value for each row when the SQLDataAdapater.Update is executed on a table?

eg. Is it possible to modify/intercept the InsertCommand, generated by the SQLCommandBuilder, to say add an output parameter, and then retrieve its value in the da.RowUpdated event???

Upvotes: 0

Views: 151

Answers (2)

Peter Klein
Peter Klein

Reputation: 1010

This is an article that has proven to be quite useful, where the trick of "tweaking the InsertCommand" is explained, as well as the trick to set the query to "Scalar"

MSDN Article (in VB.Net)

Bye!

Peter

Upvotes: 1

Pittsburgh DBA
Pittsburgh DBA

Reputation: 6783

Bill Vaughn knows a thing or two about this. They key is tweaking your InsertCommand.

See "Managing an @@IDENTITY Crisis".

Note: the actual solution uses SCOPE_IDENTITY() in order to be trigger-safe.

Upvotes: 1

Related Questions