Getting the Unique ID of a newly added record...

Results 1 to 3 of 3

Thread: Getting the Unique ID of a newly added record...

  1. #1
    Brian Jarrett Guest

    Default Getting the Unique ID of a newly added record...

    Is there any way to get the ID number from my autoincrement Primary Key immediately after posting the data for the new record? <BR>Right now I have a Customer table that has name, company, etc. in it as well as a CustomerID field. This is the field that autoincrements so I don&#039;t have the number until after I post the new data. The current ASP code I have then goes back and queries for the name again. At this point I can get the ID.<BR><BR>I&#039;m wondering if there&#039;s another way to do it without running a second query (what if I have two John Smiths?) and without having to deal with assigning incremented IDs on my own.<BR><BR>I&#039;ve tried printing out the contents of ADOREC("CustomerID") immediately after calling ADOREC.Update but it still comes up blank. I can pull all of the other information back out of the posted record, just not the ID.<BR><BR>Any ideas?

  2. #2
    Join Date
    Dec 1969

    Default Check out...

    the tips & tricks on for an example in Access and SQL Server.

  3. #3
    Jack Stow Guest

    Default RE: Getting the Unique ID of a newly added record.

    If you&#039;re using SQL Server you can do it with a stored procedure - just create a variable and do this;<BR>SET @yourvariable = @@IDENTITY <BR>straight after the INSERT of the new record - that variable will then have the ID of the record you&#039;ve just created.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts