Current location: Hot Scripts Forums » Programming Languages » ASP » return identity of access auto number


return identity of access auto number

Reply
  #1 (permalink)  
Old 08-10-06, 03:30 AM
minority minority is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
return identity of access auto number

Hi guys wondering if someone can help me with doing a retrieval of the new inserted data.

I have tried several versions found on the net but they always error does anyone have a working example of one that they could provide or a way of actuallly managing it as I am struggling with it.

I have managed to get it working

strCon.Execute("INSERT INTO Ticket(Raised_By_ID, Raised_By) VALUES(" & session("ncruserid") & ", '"& session("ncrname") &"');") ' Execute the insert command
Set rsNewID = strCon.Execute("SELECT @@IDENTITY")
intNewID = rsNewID(0) ' Store the value of the new identity in variable intNewID
rsNewID.Close
Set rsNewID = Nothing
strCon.Close

Last edited by minority; 08-10-06 at 03:54 AM.
Reply With Quote
  #2 (permalink)  
Old 08-10-06, 07:23 AM
koncept
Guest
 
Posts: n/a
that should work except that it will return the last inserted id from any table not just the one you were working with (if you have stored procedures or tiggers that will affect it) if you need something to be a little more solid let me know there are a couple other methods provied you are using ms sql
Reply With Quote
  #3 (permalink)  
Old 08-10-06, 07:27 AM
minority minority is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
this is using access I am afraid which is why I am having the issues.

i would prfer that it only gave me the id for the ticket table.
Reply With Quote
  #4 (permalink)  
Old 08-10-06, 12:39 PM
koncept
Guest
 
Posts: n/a
i have used something other than the methods listed above to do this with access, they are frowned upon but work nicely if you would like to try it....
Reply With Quote
  #5 (permalink)  
Old 08-11-06, 05:28 AM
minority minority is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
I give it a try worth leaning for at least future referance...if it is not used in this actual design... would it involve finding the max value?
Reply With Quote
  #6 (permalink)  
Old 08-11-06, 08:02 AM
koncept
Guest
 
Posts: n/a
no, it uses a record set to do the adding which is why it is frowned upon...

Code:
<%
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("_database/complaints.mdb")
dim rsAddNewUser
dim strSQl

Set rsAddNewUser = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM users"

'Query the database
rsAddNewUser.Open strSQL, strCon, 3, 2

	'Add a new record to the recordset
	rsAddNewUser.AddNew
	rsAddNewUser("first_name") =  request.Form("first_name")
	rsAddNewUser("last_name") = request.Form("last_name")
	rsAddNewUser("user_name") = request.Form("user_name")
	rsAddNewUser.Update

dim identvar    
	identvar = rsAddNewUser("identity")

'do action with identity here

	   'Reset Sever Objects 
	rsAddNewUser.close
	set rsAddNewUser = nothing
  %>

that should get you started...i have not found a way to port this over to.net, but that doesn't matter when i use .net i use ms sql...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Maximum Limits of Microsoft Access Database digioz Database 3 05-14-06 06:59 AM
Renumbering the auto number function in access minority ASP 6 06-25-05 08:21 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 10:15 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 03:52 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.