Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - autonumber retrieval and inserting.....
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

autonumber retrieval and inserting.....

 Post Reply Post Reply
Author
group1 View Drop Down
Newbie
Newbie


Joined: 20 August 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote group1 Quote  Post ReplyReply Direct Link To This Post Topic: autonumber retrieval and inserting.....
    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"
%>

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 25 August 2003 at 8:27am
Contribute to the working anarchy we fondly call the Internet
Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 25 August 2003 at 6:16pm
There have been many, many posts made throughout the world...
This was one of them.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.