Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve value of ID field

Status
Not open for further replies.

cactus1000

Programmer
Aug 31, 2001
149
US
Newbie question:

I have a simple event registration form ASP page that submits name, phone, etc.

My database has a key field called ID which is incremented automatically (there is no "ID" field in the form).

When the user submits the form data I need to somehow query the database for the ID number assigned to this particular record and alert the user if he is one of the first thirty five people to respond.

Or is there some code that would count clicks of the "submit" button (and that could be re-set to zero when the testing phase is done)?

This would be easy if "ID" was being passed from the form, but it's not.

How do I do this?
 
<%
If RS(&quot;ID&quot;) <= 35 then
response.write.....
end if
%>
I'm assuming here that you have connected to the database and created a recordset object. Have you?
admin@onpntwebdesigns.com
 
Hi ...
There is a Variable in SQL Named &quot;@@Identity&quot; which gives you the last-inserted identity value.
so let's say that your table name is &quot;MyTable&quot; and you have inserted a record in it just now.
after inserting the record you just have to do this :
DBConn.Execute(&quot;SELECT @@Identity FROM MyTable&quot;).Fields(0).Value
DBConn is the name of the connection object.

TNX.
E.T.
 
Thanks to both! I'm using onpnt's idea for now but I'll try the SQL approach if this doesn't fully work out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top