Print Page | Close Window

retrieve Database ID

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=2782
Printed Date: 28 March 2026 at 9:08am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: retrieve Database ID
Posted By: 288enzo
Subject: retrieve Database ID
Date Posted: 16 May 2003 at 8:30pm

On my page that posts all data to my database I have added the following in hopes to see what the number was of the new record I just added.

rsAddListing.Update

intIDNumber = request.form("id")

response.write "New record number is " & intIDNumber

My problem is that I don't get the new record number to appear.  Is there some sort of trick that I am missing.  Please help...

 




Replies:
Posted By: Bunce
Date Posted: 16 May 2003 at 10:10pm

You need to get the ID from the database, not the querystring.

Do a search for @@IDENTITY on google. Should help you out.

Cheers,
Andrew



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


Posted By: 288enzo
Date Posted: 16 May 2003 at 10:18pm
I'm sorry, I forgot to mention that I tried @@Identity already and had no success.


Posted By: Bunce
Date Posted: 17 May 2003 at 12:37am

If you're using Access 2000+ or SQL Server then you're doing it wrong.



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


Posted By: 288enzo
Date Posted: 17 May 2003 at 8:39am
Bunce, I am using Access 2002.  What is it that I am doing wrong?


Posted By: Bunce
Date Posted: 17 May 2003 at 8:49am

How are we meant to know without showing us your code!!

Have you searched the many articles on the net for the code to do what you want?  There are HEAPS of examples.



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


Posted By: 288enzo
Date Posted: 17 May 2003 at 6:24pm

I have tried many, many, many different ways of doing this.  I have been to many, many different web sites that offer code and nothing is working.

My code:

<%
Dim adoCon    
Dim rsAddListing  
Dim strSQL   
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("..........")
Set rsAddListing = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT tblListings.ID, tblListings.city, tblListings.structure FROM tblListings;"
rsAddListing.CursorType = 2
rsAddListing.LockType = 3
rsAddListing.Open strSQL, adoCon
rsAddListing.AddNew
rsAddListing.Fields("city") = Request.Form("city")
rsAddListing.Fields("structure") = Request.Form("structure")
rsAddListing.Update

intIDNumber = rsAddListing.Fields("ID")

response.write "before " & intIDNumber & " after"

Dim objNewMail
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
objNewMail.From = " mailto:webmaster@ocbeachrentals.net - .......... "
objNewMail.To = request.form("email")
objNewMail.Subject = "New Listing #" & intIDNumber
objNewMail.Body = "....."
objNewMail.Send
Set objNewMail = Nothing

rsAddListing.Close

Set rsAddListing = Nothing
adoCon.Close
Set adoCon = Nothing

%><head><title>Post New Listing to Database</title></head>



Posted By: 288enzo
Date Posted: 17 May 2003 at 8:53pm

Thanks everyone, but I figured it out.  All I needed to do was add the following after my update statement.

rsAddListing.movelast

and that did it.




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