Returning Auto-Increment Value

mesaexplorerbc1
09-22-2006, 10:55 PM
Hey Everyone,

I have a form that when submit is clicked, it stores the form data into an MSSQL DB. There is a column (Application_ID) in the DB that is Auto-Increment and is the Primary Key.

Also, this form sends an email to the customer stating that their information has been received.

What I'd like to do is include the New Record's Application_ID in the email. However, the value is not assigned until the record is saved to the DB. Could someone kindly point me in the right direction to find the new record and pull it's Application_ID so that it can be included within the email?

Thanks all!!

reboot
09-23-2006, 06:58 AM
select @@identity as newid from table

mesaexplorerbc1
09-23-2006, 12:05 PM
Thanks for the reply reboot. Is @@identity the best way to do this? I've read that if there are multiple people adding at the same time that there's a possibility of it returning the wrong ID. Also, would you be so kind as to help with a line of code or 2. Here's what I tried, with no success.


Sql1.SelectCommand = "SELECT @@identity as newid FROM Registrations"
Sql1.Select()


Sorry, I'm still really new to SQL Commands. Thanks for your help!!!

wayneph
09-24-2006, 02:01 PM
If you're using Transactions, or a Stored Procedure you can use SCOPE_IDENTITY().

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum