SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast drorit30's Avatar
    Join Date
    May 2003
    Location
    tel aviv
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting the new ID from SQL server after row creation

    Hi all,

    I have a table in sql which has a field ID (integer which increments automatically - autonumber)

    After i create a new row i want to send out an email which links to the ID of the new row just created.


    LocalRecordset.AddNew
    LocalRecordset("name") = new_name
    LocalRecordset("email") = new_email
    LocalRecordset.Update

    Send email with link = www.123.com/info.asp?id=LocalRecordset("id")
    This doe not work on SQL server, but it does work on ACCESS.

    I know I can query the table again with the fields I just entered in the new row, but is there another way to do this like it is done in ACCESS?

    Thanks in advance,
    Dror

  2. #2
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Google is your friend.

    Key words to look in Books Online for are SCOPE_IDENTITY and IDENT_CURRENT.

    (NOT @@IDENTITY as some people think).

  3. #3
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    declare a variable and set the variable to be the newID

    delcare @newID int
    select @newID = scope_identity()
    then apply it to your query string


Bookmarks

Posting Permissions

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