I’m using ADO.NET to try to get the value I’m about to insert before I insert it in SQL Server 2005. SCOPE_IDENTITY() works fine after, but I’m also inside a transaction if that makes a difference. I literally need to select the next ID, and only the ID and have it available to C# before the insert.
Share
The SCOPE_IDENTITY will only work once you’ve inserted the row in to the table. If you need to know the value before you insert you will need to use IDENT_CURRENT(‘table_name’). See http://msdn.microsoft.com/en-us/library/ms175098.aspx for more information.