get new SQL record ID

前端 未结 8 2064
南方客
南方客 2020-12-17 19:31

How can I get back the autogenerated ID for a new record I just inserted? (Using ASP classic and MSSQL 2005)

8条回答
  •  渐次进展
    2020-12-17 19:59

    You run the query

    select scope_identity()
    

    using the same database connection, before doing anything else with it. The result is, as you probably expect, a record set containing a single row that has a single field. You can access the field using index 0, or you can give it a name if you prefer that:

    select scope_identity() as lastId
    

提交回复
热议问题