Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Get ID from a DB Field after INSERT
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Get ID from a DB Field after INSERT

 Post Reply Post Reply Page  <12
Author
d088 View Drop Down
Newbie
Newbie


Joined: 02 December 2004
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote d088 Quote  Post ReplyReply Direct Link To This Post Posted: 03 December 2004 at 1:07pm
Well, now I've hit another problem...  Any more help would once again be appreciated.

<>Microsoft VBScript runtime error '800a000d'
Type mismatch: 'sql2'
/hp04/test/register_confirm.asp, line 32



sql2="SELECT TOP 1 pk_Reg_ID FROM Primary_Registrations ORDER BY pk_Reg_ID DESC;"
connAuction.execute(sql2)

Session("reg_ID")=sql2("pk_ID")    &nb sp;         &nb sp;       <!--LINE 32

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

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 03 December 2004 at 1:48pm
sql2 is a string variabke, you need to reference the recordset.
Back to Top
d088 View Drop Down
Newbie
Newbie


Joined: 02 December 2004
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote d088 Quote  Post ReplyReply Direct Link To This Post Posted: 03 December 2004 at 2:57pm
Thank you!

Here's the final code for anyone that has a similar problem...

<%
'INSERT FORM INFORMATION INTO DATABASE

If request.form("FName")<>"" Then FName= request.form("FName") Else FName= "None"
If request.form("LName")<>"" Then LName=request.form("LName") Else LName="None"
If request.form("Company")<>"" Then Company=request.form("Company") Else Company="None"
If request.form("Phone")<>"" Then Phone=request.form("Phone") Else Phone="None"
Fax="NULL"
If request.form("Email")<>"" Then Email=request.form("Email") Else Email="None"
If request.form("Address1")<>"" Then Address1=request.form("Address1") Else Address1="None"
If request.form("Address2")<>"" Then Address2=request.form("Address2") Else Address2="None"
If request.form("City")<>"" Then City=request.form("City") Else City="None"
If request.form("State")<>"" Then St=request.form("State") Else St="None"
If request.form("Zip")<>"" Then Zip=request.form("Zip") Else Zip="None"
If request.form("Cancellation_Agreement")<>"" Then Cancellation_Agreement=request.form("Cancellation_Agre ement") Else Cancellation_Agreement=None
If request.form("Amount_Due")<>"" Then Amount_Due=request.form("Amount_Due") Else Amount_Due="None"
If request.form("IP")<>"" Then IP=request.form("IP") Else IP="None"

myDSN="DSN=hp04"
set connAuction=server.createobject("adodb.connection")
connAuction.open myDSN

sql="INSERT INTO Primary_Registrations (FName, LName, Company, Position, Phone, Email, Address1, Address2, City, St, Zip, Cancellation_Agreement, Amount_Due, IP) VALUES ('"&FName&"', '"&LName&"', '"&Company&"', '"&Position&"', '"&Phone&"', '"&Email&"', '"&Address1&"', '"&Address2&"', '"&City&"', '"&St&"', '"&Zip&"', '"&Cancellation_Agreement&"', '"&Amount_Due& ;"', '"&IP&"')"
connAuction.execute(sql)
connAuction.close
%>

<%
myDSN="DSN=hp04"
set conn2Auction=server.createobject("adodb.connection")
conn2Auction.open myDSN
set rsAuction=server.createobject("adodb.recordset")
getID="SELECT TOP 1 pk_Reg_ID FROM Primary_Registrations ORDER BY pk_Reg_ID DESC;"
rsAuction.open getID, myDSN

set Session("reg_ID")=rsAuction.Fields("pk_Reg_ID")
%>

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: 04 December 2004 at 4:42am
Really shoudldn't be using 'Select Top 1' - too risky.

Check out the links I posted.  They implemented that feature exactly for the reason that you *wouldn't* have to run another query...
There have been many, many posts made throughout the world...
This was one of them.
Back to Top
 Post Reply Post Reply Page  <12

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.