|
-
Jun 11th, 2001, 04:47 AM
#1
Thread Starter
Hyperactive Member
get auto_increment field after addnew ?
If I add a record to a table (with addnew or whatever) and this table has an auto_incrementing field (as a unique identifier) how do I retrieve this identifier (without having to execute a new query) ?
-
Jun 11th, 2001, 06:17 AM
#2
Black Cat
If the db cursor is on the new record when you call the .Update function (I would think it would be, just look at .Fields("AutoID") or whatever you called it, right after the Update.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Jun 11th, 2001, 08:33 AM
#3
Thread Starter
Hyperactive Member
Nope this does not work. If I do this f.i.:
objRS.Open "table",objConn,0,3,2
objRS.AddNew
objRS("Name") = strName
objRS("Pass") = strPass
Response.Write "ID = " & objRS("ID")
objRS.Update
Response.Write "ID = " & objRS("ID")
I get:
ID = ID =
-
Jun 11th, 2001, 10:02 AM
#4
Addicted Member
Here is an example of something that I recently used.
PHP Code:
'Save the data
Set tmpRS = Server.CreateObject("ADODB.Recordset")
Set tmpConn = Server.CreateObject("ADODB.Connection")
tmpSQL = "SELECT * FROM realestate_properties"
tmpConn.ConnectionTimeout = DATABASE_CONNECTION_TIMEOUT
tmpConn.Open DATABASE_CONNECTION_STRING
tmpRS.Open tmpSQL, tmpConn , adOpenKeyset, adLockOptimistic
tmpRS.AddNew
tmpRS.Fields("realestate_company_id").Value = gCompanyId
tmpRS.Fields("realestate_owner_firstname").Value = PadSQL(get_form("ownerfirstname"))
tmpRS.Fields("realestate_owner_lastname").Value = PadSQL(get_form("ownerlastname"))
tmpRS.Fields("realestate_owner_home_phone").Value = PadSQL(get_form("ownerhomephone"))
tmpRS.Fields("realestate_owner_work_phone").Value = PadSQL(get_form("ownerworkphone"))
tmpRS.Fields("realestate_owner_address").Value = PadSQL(get_form("owneraddress"))
tmpRS.Fields("realestate_owner_city").Value = PadSQL(get_form("ownercity"))
tmpRS.Fields("realestate_owner_state").Value = PadSQL(get_form("ownerstate"))
tmpRS.Fields("realestate_owner_zipcode").Value = PadSQL(get_form("ownerzipcode"))
tmpRS.Fields("realestate_property_address").Value = PadSQL(get_form("propertyaddress"))
tmpRS.Fields("realestate_property_city").Value = PadSQL(get_form("propertycity"))
tmpRS.Fields("realestate_property_state").Value = PadSQL(get_form("propertystate"))
tmpRS.Fields("realestate_property_zipcode").Value = PadSQL(get_form("propertyzipcode"))
'Update
tmpRS.Update
'get the new property id (auto-incremented field)
get_property_id = tmpRS.Fields("realestate_id")
Set tmpRS = Nothing
Set tmpConn = Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|