AllExperts > Active Server Pages Programming (ASP) 
Search      
Active Server Pages Programming (ASP)
Volunteer
Answers to thousands of questions
 Home · More Active Server Pages Programming (ASP) Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ashley Brazier
Expertise
Main focus is ASP, SQL Server 2000 & 2005

Experience
Over 6 years experience.

Education/Credentials
BCs Honours Software Design and Networks

 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > Get inserted Record ID

Active Server Pages Programming (ASP) - Get inserted Record ID


Expert: Ashley Brazier - 3/4/2009

Question
QUESTION: I will Get Right to it. I am using classic asp pages to develop my site. I am trying to query the database for a single value, and plug that value into a session variable.
the query I run is something like this. Select ID from from cars where cars = blue and year = 2009.
I need to know how to return the single value an place its value into a session variable

ANSWER: <%
Dim Conn
Dim SQLTemp

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.connectionstring =
  "Provider=Microsoft.Jet.OLEDB.4.0;Data
  Source=" & Server.MapPath("\yourdb.mdb")& ";"
Conn.Open

SQLTemp = "SELECT * FROM yourTable"
set rstemp=Conn.execute(SQLTemp)

Do While Not rstemp.EOF

rstemp.Fields("whateverdatabasefield").Value

rstemp.MoveNext
Loop

Conn.Close
Set Conn = Nothing
%>

---------- FOLLOW-UP ----------

QUESTION: How can I Get the Id of a newly inserted record. The Id field is a auto number

Answer
sql_insert = "set nocount on ; insert into reservas (turnier_id, firstname, lastname, xtel, xdni, xplz, xtown, email, startdate, startmonth, enddate, endmonth, PLZ, town, country, xtitel, xtime, extra, region, res1, res2, res3, res4 ) values("&turnier_id&", '"&firstname&"','"&lastname&"','"&xtel&"','"&xdni&"','"&xplz&"','"&xtown&"','"&email&"', "&startdate&","&startmonth&","&enddate&","&endmonth&",'"&PLZ&"','"&town&"','"&country&"','"&xtitel&"','"&xtime&"','"&extra&"','"®ion&"','"&res1&"','"&res2&"','"&res3&"','"&res4&"'); select scope_identity() id "
'response.write sql_insert
conn = StrAdminProvider
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open sql_insert, conn
id_number=rs("id")

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.