Hello,
I am doing Insert using SqlTransaction but I need to get primary key of last Inserted table to use it in next statement. I don't want to commit the transaction before complete insert in second table. so how to get primary key in SQLTransaction before commit it
Thanks

Munesh SharmaPosted Apr 12, 2014, 8:24 AM
Use SCOPE_IDENTITY() just after the INSERT
--
DECLARE @newId INT
INSERT INTO MyTable1(
Field1
)
SELECT @MyVal1
--End of Insert here
SELECT @newId = SCOPE_IDENTITY()
--Rest of the procedure
Ajay PatelPosted Apr 22, 2014, 6:29 AM
SELECT IDENT_CURRENT ('table Name') AS Current_Identity;