Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2002
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to find out what's the next record

    Hi! I told I'd be back...

    Today's problem is this:
    I have in my database (SQL Server 7.0) a table with a field that uses automatic increment. When I add a new record through a ASP form, I need to know the number of the record in which are going to store the data, in order to use that record number in another table.

    Now, I'm using "cont = objrecordset.RecordCount + 1", but if a record is deleted, this is going to be wrong, because the "recordcount + 1" is not the number of the record that is going to be used. (I hope this is not so confusing as it seems to me now...)

    So, to make it simple, I need to know the number that the database is going to store the data. Is there a way, or I have to do my one increment?

    Thank's
    Paula

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Here is a page that gives a very good way of doing this in SQL Server:
    http://www.aspfaqs.com/webtech/tips/t122600-1.shtml

    Here is a more generic way of doing it. You must include the standard adovbs.inc file or change the last three variables in the RS.open line to be their static values.

    Code:
    RS.Open tableName, yourAlreadyOpenConnection, adOpenKeySet, adLockOptimistic, adCmdTable
    RS.AddNew
    RS("field1") = value1
    RS("field2") = value2
    ...
    RS("fieldN") = valueN
    RS.Update
    idOfAddedRecord = RS("nameOfAutonumberField")
    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=79

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, that's a neat trick. Thanks!
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    New Coder
    Join Date
    Nov 2002
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yep! It worked just fine!

    Thank's a lot!

    Paula


  •  

    Posting Permissions

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