|
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" %>
|