Click to See Complete Forum and Search --> : Pulling Auto Number from database


ejrhodes
05-06-2003, 01:07 PM
Guys,

Is there a way to pull the auto-number of a row entered into a database? IE, if I create an order, automatically pull the order_no from the order_table so that I can insert it into an order_detail table. There has to be a better way then selecting max order_id because that might not be the most current order?

I know there is a buiilt in function in php what about asp?

THanks

cmelnick
05-06-2003, 02:33 PM
Not exactly sure if this is what you want, and I haven't tested the following, but if you are using ADO, you should be able to do:


rstOrderTable.AddNew "item, qty, cost","'baseball', 1, '1.25'"
rstOrderTable.Update


The recordset should be pointing to the record you just added, so you should be able to say:

newID = rstOrderTable("order_no")

or whatever your auto-number order number is.

Hope this helps.

Check out http://www.w3schools.com/ado/ado_ref_recordset.asp for more information on ADO recordset objects.

Bullschmidt
05-07-2003, 02:46 AM
4GuysFromRolla.com : ASP FAQS : Databases, General
How do I get the record number of a just added record, using an Access database table? by Bill Wilkinson - 11/3/2000
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=79