C# Scope Identity
s
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 11, 2012, 9:57 PM EDT
Hope It Helped. Please Check This is Currect Answer.
Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 11, 2012, 9:12 PM EDT
(In your case you will get value as 0 as there are no changes in identity column in current scope).
To achieve what u want
1.You can use @@Identity which returns Identity value inserted regardless of the table and scope(so it may help)
2.Ident_Current('tableName') which return the last identity value generated for a specific table in any session and scope.
3.Create Stored Procedure and put your insert query followed by Select Scope_Identity() and front end execute Stored Procedure using the same syntax.
Hope It Helped. Please Mark answer as Accepted Answer.
bagzli36 reputationPosted Aug 11, 2012, 9:27 PM EDT
Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 11, 2012, 9:35 PM EDT
Can u do like this
string sqlStatement = InsertQuery + ";SELECT SCOPE_IDENTITY()";
Even this will work.
Hope It Helped. Please Mark answer as Accepted Answer.
bagzli36 reputationPosted Aug 11, 2012, 9:54 PM EDT
bagzli36 reputationPosted Aug 11, 2012, 10:05 PM EDT
Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 11, 2012, 10:50 PM EDT