Returning autonumber on Insert

Results 1 to 2 of 2

Thread: Returning autonumber on Insert

  1. #1
    Join Date
    Dec 1969

    Default Returning autonumber on Insert

    Hi,<BR><BR>I am trying to get the value of an autonumber field when I insert a new record.<BR><BR>I am using ODBC to connect to my database.<BR>It is a ticket producing script which takes the values for the company Employee (emname), Their Guest (guname), if he/she is a vegetarian (vege) and the starter they have chosen (starter).<BR>The AUTONUMBER is the Ticket Number (Ticknum).<BR>Here is the code I have so far...<BR><BR>&#060;%<BR>emname = request.form ("emname")<BR>guname = request.form ("guname")<BR>vege = request.form ("vege")<BR>starter = request.form ("starter")<BR><BR>set db = server.createobject ("adodb.recordset")<BR>sqltext="insert into tickets (emname, guname, vege, starter) values (&#039" & emname & "&#039,&#039" & guname & "&#039,&#039" & vege & "&#039,&#039" & starter & "&#039)"<BR> (sqltext),"dsn=bcsb"<BR><BR>ticknum=db("ticknum")< BR><BR>%&#062;<BR><BR>The Error is : <BR><BR>ADODB.Recordset error &#039 800a0e78&#039 <BR><BR>The operation requested by the application is not allowed if the object is closed. <BR><BR>Your help is greatly appreciated.

  2. #2
    Join Date
    Dec 1969

    Default RE: Returning autonumber on Insert

    Hi,<BR><BR>If you are using SQL Server 7.0 as your database, you could write a stored procedure and return the value of the ticket number. This is captured in the front-end using the ADO Command Object. Use ADO Command Object, it is very powerful.<BR>If Ticket number is an identity column in SQL table, use the @@IDENTITY function in the SP to return the value.<BR><BR>Sundar

Posting Permissions

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