Print Page | Close Window

autonumber retrieval and inserting.....

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5261
Printed Date: 30 March 2026 at 4:44pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: autonumber retrieval and inserting.....
Posted By: group1
Subject: autonumber retrieval and inserting.....
Date Posted: 25 August 2003 at 4:25am

I have the following code which i want to retrieve the Autonumber from the inserted data into the database and show this number to the user. what am i doing wrong??

 

Also if i wanted to add data to an additional table using some of the data passed from a form, how would i do this? thanks

<!-- #include file="adovbs.inc" -->
<%
'Dimension variables
Dim adoCon              'Holds the Database Connection Object
Dim rsAdd   'Holds the recordset for the new record to be added
Dim strSQL               'Holds the SQL query to query the database
Dim iRecordAdded

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("./db/database.mdb")


'Create an ADO recordset object
Set rsAdd = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT Bookings.* FROM Bookings;"

'Set the cursor type we are using so we can navigate through the recordset
rsAdd.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsAdd.LockType = 3

'Open the recordset with the SQL query
rsAdd.Open strSQL, adoCon

'Tell the recordset we are adding a new record to it
rsAdd.AddNew

'Add a new record to the recordset

rsAdd.Fields("DateArrive") = Request.Form("arrive")
rsAdd.Fields("DateDepart") = Request.Form("depart")
rsAdd.Fields("Paid") = Request.Form("paid")
rsAdd.Fields("DateMade") = Request.Form("date")
rsAdd.Fields("Comments") = Request.Form("comments")

'Write the updated recordset to the database
rsAdd.Update

iRecordAdded = rsAdd.Fields("id").Value
Response.Write "<p>Record id " & iRecordAdded & " added!</p>" & vbCrLf

'Reset server objects
rsAdd.Close
Set rsAdd = Nothing
Set adoCon = Nothing
Response.Redirect "booking2.asp"
%>




Replies:
Posted By: MorningZ
Date Posted: 25 August 2003 at 8:27am

this code sample might help :)

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=79 - http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=79



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Bunce
Date Posted: 25 August 2003 at 6:16pm
here's another:
http://www.adopenstatic.com/Experiments/FastestAutonumber.asp - http://www.adopenstatic.com/Experiments/FastestAutonumber.asp

-------------
There have been many, many posts made throughout the world...
This was one of them.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net