return id after inserting record

Results 1 to 3 of 3

Thread: return id after inserting record

  1. #1
    Jason Eilert Guest

    Default return id after inserting record

    I am trying to insert a record into a database table and I want to retrieve an ID field from that record after I insert it. The ID field is an autonumber. How would you do that? Some sample code would be helpful.<BR><BR>Thank you in advance

  2. #2
    Join Date
    Dec 1969

    Default RE: return id after inserting record

    I do the same thing with my coding. Here&#039s a sample:<BR><BR>some notes:<BR>-newid is an alias and is a dummy value<BR>-usertype is a dummy field<BR>-max is what you need to use, it is not customizable<BR>-i write a cookie w/ the value of that field, this is for identity when they come back to the, however, can do what you please with it<BR><BR>&#060;%<BR>set dbcn=Server.CreateObject("ADODB.Connection")<BR>db cn.Open "DSN=intranet"<BR>set dbrs=Server.CreateObject("ADODB.Recordset")<BR>dbr s.ActiveConnection=dbcn<BR>dbrs.Open "insert into customer (usertype) values (1)",,3,4<BR>dbrs.Open "select max(userid) as newid from customer",,3,4 <BR>userid=dbrs.Fields("newid")<BR>Response.Cookie s("yum").Expires= #July 4, 2004#<BR>Response.Cookies("yum")("userid")=dbrs.Fi elds("newid")<BR>dbrs.Close<BR>%&#062;

  3. #3
    Jason Eilert Guest

    Default RE: return id after inserting record

    thank you very much

Posting Permissions

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