Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value
Returning Auto-Increment Value Returning Auto-Increment Value
Returning Auto-Increment Value
Go Back  Xtreme Visual Basic Talk > > > Returning Auto-Increment Value


Reply
 
Thread Tools Display Modes
  #1  
Old 09-22-2006, 10:55 PM
mesaexplorerbc1 mesaexplorerbc1 is offline
Regular
 
Join Date: Jan 2004
Location: Gresham, OR
Posts: 61
Question Returning Auto-Increment Value


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!!
Reply With Quote
  #2  
Old 09-23-2006, 06:58 AM
reboot's Avatar
rebootReturning Auto-Increment Value reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

select @@identity as newid from table
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #3  
Old 09-23-2006, 12:05 PM
mesaexplorerbc1 mesaexplorerbc1 is offline
Regular
 
Join Date: Jan 2004
Location: Gresham, OR
Posts: 61
Default

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.

Code:
Sql1.SelectCommand = "SELECT @@identity as newid FROM Registrations"
Sql1.Select()
Sorry, I'm still really new to SQL Commands. Thanks for your help!!!
Reply With Quote
  #4  
Old 09-24-2006, 02:01 PM
wayneph's Avatar
waynephReturning Auto-Increment Value wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

If you're using Transactions, or a Stored Procedure you can use SCOPE_IDENTITY().
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value Returning Auto-Increment Value
Returning Auto-Increment Value
Returning Auto-Increment Value
 
Returning Auto-Increment Value
Returning Auto-Increment Value
 
-->