Solved

Get ID of record you just inserted

Posted on 2009-04-03
4
375 Views
Last Modified: 2012-05-06
How do I capture the ID of the record I just inserted into DB.

column name is ID.
SQL = "INSERT INTO homeFormUsers (firstName,lastName,emailAdd, ipAddress, interestedIn, datesubmitted)" 
SQL = SQL & "VALUES ('" & strFname & "','" & strLname & "','" & strEmailAdd & "','" & strIP & "','" & strIntersted & "','" & strCurrDateTime & "')"
objConn.execute SQL

Open in new window

0
Comment
Question by:pGustafson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24060966
this should do (presuming it's a identity
SQL = "SET NOCOUNT ON; INSERT INTO homeFormUsers (firstName,lastName,emailAdd, ipAddress, interestedIn, datesubmitted)" 
SQL = SQL & "VALUES ('" & strFname & "','" & strLname & "','" & strEmailAdd & "','" & strIP & "','" & strIntersted & "','" & strCurrDateTime & "'); SELECT SCOPE_IDENTITY() ID "
dim rst
set rst = objConn.execute(SQL) 
response.write rst.fields("ID").Value

Open in new window

0
 

Author Comment

by:pGustafson
ID: 24061038
When I use that I get:

ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24061088
you must have applied the suggested change incompletely.
either the SET NOCOUNT ON is missing, or the ID after SCOPE_IDENTITY() ...
0
 

Author Closing Comment

by:pGustafson
ID: 31566283
Thanks that worked!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question