Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get UniqueID when insert with recordset

Status
Not open for further replies.

thankgodfortektips

Programmer
Dec 20, 2005
95
KY
Hey Guys,

I have an SQL2000 db and inserting records with via a recordset from an ASP page. I need to be able to get the unique key of the record just added.

I have searched the forums and google and it seems that some people have had succcess with the method used in thread333-1107949. I would much prefer to add the record this way then an insert statement.

When I try the code from thread333-1107949 I dont get any error the unique_ID is just blank...

Anyone any ideas???
 
use ADO component

objRS.AddNew
objRS("Name") = "xyz"
objRS.Update
intID = objRS("ID")

 
Hey, Thanks kitkit, but I dont quite understand what you mean...

below is my existing code

Dim RS
Dim unique_ID
Set RS = Server.CreateObject("ADODB.RecordSet")
' Open the table
RS.Open "Tbl_Address", MM_connProgram_STRING, adOpenKeySet, adLockPessimistic, adCmdTable
' Add a new record
RS.AddNew
RS("Contact") = "test"

' Update the record
RS.update
' Retrive the ID
unique_ID=RS("ID")
' Close the RecordSet
RS.Close
Set RS = Nothing


How would I adapt it to take your advise into consideration? Thanks in advance...
 
Me again... quick question... I have to include this line in the code for it to work.

<!--#include file="adovbs.inc" -->

but I already have an include file in the asp page. I have tried putting the adovbs.inc code into the existing include file, and also tried putting <!--#include file="adovbs.inc" --> in the existing include file but didn't get anywhere... Anyone have any idea where to go from here?
 
you should have no problem including multiple files. You have the adovbs in your root directory correct?


____________ signature below ______________
General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
I am sorry, you are correct... I had tried adding the 2 include lines, but left an error in one of them. thought I was getting the error because of the 2 include lines...

thanks everyone!
 
Rather than include that long sizable file into every page for your database constants, try adding the type library into the global.asa file as it should be more performant:

Code:
<!--METADATA
TYPE="TypeLib"
NAME="Microsoft ActiveX Data Objects 2.6 Library"
UUID="{00000206-0000-0010-8000-00AA006D2EA4}"
VERSION="2.6"
-->

or (alternative method)

<!--METADATA 
TYPE="typelib" 
FILE="C:\Program Files\Common Files\System\ADO\msado20.tlb"
-->
(This needs to go in the top of the global.asa file, and is for ADO v2.6 (top example) and 2.0 (bottom example) - if you have a lower version then you will need to change the details / path etc)

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top