Results 1 to 4 of 4

Thread: Get Identity number after insert record

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    NB imagine the ID field is called MainID . . . . .

    VB Code:
    1. rst.Open "SELECT * FROM tblMain WHERE 1=2", gconnSQL, adOpenKeyset, adLockPessimistic ' Blank ADO recordset
    2. rst.AddNew
    3. rst.Fields("MainDate") = DateSerial(2002, 2, 25)
    4. rst.Fields("MainTimestamp") = DateSerial(2002, 2, 25) & " " & TimeSerial(8, 0, 0)
    5. rst.Fields("MainDetail") = rstSQL.Fields("MachineSerial")
    6. rst.Update

    Then the value for rst.Fields("MainID") will be the value you require.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    If you're using a MS-SQL stored procedure to do the insert, you can immediately get the @@IDENTITY value after the insert and save it to an output parameter.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    Quite true . . .
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  4. #4
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    Both work.

    Thanks.

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