Results 1 to 11 of 11

Thread: Field ID

  1. #1
    chenko
    Guest

    Field ID

    Im adding a new record to a database using ASP.

    The problem is i want to create a new record which i can do fine, and get the ID fields value that is set to autonumber, whats the easiest way to do this?

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Read the last record's autonumber, increment it, and put it back in. Though it may yell at you since it's an automatic field.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    chenko
    Guest
    What if there is another record put in before I can read that field?

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Then you could get the numberofrecords from the recordset object and increment that to put into your autonumber field.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    chenko
    Guest
    That wouldnt work if there are going to be records deleted will it? I could always turn autonumber off.

  6. #6
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    chenko,

    Couldn't you just grab the FieldID right after you insert the new record by moving to the last record?
    Maybe by combining these procedures into the same sub or function?


    Chris
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  7. #7
    chenko
    Guest
    They are in the same sub/function. Right after the .Update I want to get it....

    If I add a record, will I have to reopen the recordset to get the new entry?

  8. #8
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    If you already have the recordset open I don't see why you would, maybe I'm wrong. Try moving to the last record after the insert, grab the ID and see if they match.


    Chris
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  9. #9
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Are you using Insert statements or are you using the AddNew method of the recordset object?

    If your using the later, ADO moves the cursor to the newly added record so just read in the value. If your using Insert statements, then what your describing is an issue.

    If you need to add new records AND you need to load them immediately for use, you should use the AddNew method and make sure your recordset is adOpenKeySet or adOpenDynamic and your lock type is not adReadOnly.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  10. #10
    chenko
    Guest
    I am using the AddNew statment, and im using a Update query after, I have it open for adOpenDynamic


    Cheers

  11. #11
    chenko
    Guest
    Ok I got back around trying that and it works

    Cheers!!

Posting Permissions

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



Click Here to Expand Forum to Full Width