Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Returning @@ identity from a stored procedure to a .cs page

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-10-04 : 07:42:54
Kavvya writes "Sometimes when you insert a record into your SQL database using ASP, you want to get the identity value of the row you just inserted. Imagine, for example, that you allow a user to create a profile. When a user creates a new profile, a new row is inserted into a table called CustomerProfile. Let's say CustomerProfile has thefollowing rows: an integer identity column / primary key named CustomerProfileID; a varchar(30) column named CustomerName; and a tiny int character field called CustomerAge.

As soon as the user enters their information and clicks "Save", you want them to be taken to the profile editing screen,where they will see the information they just entered and can edit the values and update their profile. This is where @@identity will be useful.

I would be grateful if you could tell me how a stored procedure will return @@identity and how this value can be obtained in the function containing the call to the stored procedure in question."

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2006-10-04 : 07:49:10
In the beginning of your procedure make sure you have "SET NOCOUNT ON" and then at the end you write something like this: "SELECT SCOPE_IDENTITY() as InsertedID". Then in your asp directly after the insert you need to fetch the new ID: NewID = RS("InsertedID").

Alternatively you could (should?) use the command-object and a stored proceudre return value...

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-04 : 07:54:22
Use parameters instead.
Have a look at this topic http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=70783


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -