Return Inserted Identity from Stored Procedure

Posted by Zu on April 23, 2010 in ASP |

Stored Procedure looks like this:

ALTER PROCEDURE [dbo].[spInsertSomething]
@txtName varchar(255),
@txtDisplayName varchar(80),
@txtPhone varchar(50)
AS
BEGIN
INSERT INTO tblSomeTable
(
txtName ,
txtDisplayName ,
txtPhone
)
VALUES
(
@ txtName ,
@ txtDisplayName ,
@ txtPhone
)
SELECT NEWID = SCOPE_IDENTITY()
END

asp code:

Set cmd = Server.CreateObject("ADODB.Command")

Set cmd.ActiveConnection = adoCn

cmd.CommandText = "spInsertSomething"

cmd.CommandType = 4

cmd.Parameters(1).Value = txtName

cmd.Parameters(2).Value = txtDisplayName

cmd.Parameters(3).Value = txtPhone

Set insertProgram2Results = cmd.Execute

Response.Write insertProgram2Results("NEWID ")

set PersonID = insertProgram2Results("NEWID ")

Set cmd = Nothing

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2007-2012 Cheat Sheet All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.