In order to insert a row into the database and get the newly inserted ID, you need to execute the following steps:
to execute insert operation (Instead of
2. Execute another SQL statement "
" and use
to get the newly inserted ID.
I would recommend you to create a Stored Procedure to carry out the overall task. Following is a very simple stored procedure which does that:
CREATE PROCEDURE dbo.SAVE_TEMPLATE(
, @Name varchar(255)
, @GeneratedID INT OUTPUT
INSERT INTO dbo.Table (Name)
SET @GeneratedID = SCOPE_IDENTITY();
Hope this helps.