kevind
Posts: 251
|
Posted: 12/30/2010, 2:16 PM |
|
hi all,
I'm using standard ASP 3.0 with mySQL for a new project - so far, all the mySQL stuff is working out (first project with mySQL instead of Access).
I need to pick up the last inserted id from mySQL in the After Insert event code of a record form.
I want to use the open connection to the database if possible - I'm assuming the publicly declared CONNECTION variable would still be CONNECTED to the database at this point so I"m using
With Connection
SQL="select last_inserted_id() as lst"
.execute(SQL)
??
End With
questions are
1) can I use the connection the recordset already has open or do i need to make a new one
2) where I have the ?? above, is there a single line I can use to assign the returned ID to a variable or session variable?
3) if no to 1 and 2 above, I assume declaring a recordset against the SQL state will allow me to spin through the recordset and pick up the ID
any help appreciated
Kevin
_________________
thanks
Kevin
======================
CCS 3.2.x / ASP / MS Access /mySQL / PHP / jQuery / jQuery UI / jQuery Mobile
|
|
|
kevind
Posts: 251
|
Posted: 12/30/2010, 2:29 PM |
|
never mind - figured it out myself - in the after insert section of the record I simply created a dlookup action that saves the 'last_insert_id()' from the table name I was inserting into to a session variable - easy
follow-up question though - is this last_insert_id(), my last inserted id or the last one any user has inserted ?
_________________
thanks
Kevin
======================
CCS 3.2.x / ASP / MS Access /mySQL / PHP / jQuery / jQuery UI / jQuery Mobile
|
|
|
Oper
Posts: 1195
|
Posted: 01/13/2011, 11:31 AM |
|
Last Inserted ID of that Connection
In Resume User Section/Connection.
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)
http://www.PremiumWebTemplate.com
Affiliation Web Site Templates
Please do backup first |
|
|
kevind
Posts: 251
|
Posted: 01/14/2011, 3:24 AM |
|
Thanks all for the information.
_________________
thanks
Kevin
======================
CCS 3.2.x / ASP / MS Access /mySQL / PHP / jQuery / jQuery UI / jQuery Mobile
|
|
|
azzarev
Posts: 9
|
Posted: 07/08/2013, 7:57 AM |
|
Quote kevind:
never mind - figured it out myself - in the after insert section of the record I simply created a dlookup action that saves the 'last_insert_id()' from the table name I was inserting into to a session variable - easy
follow-up question though - is this last_insert_id(), my last inserted id or the last one any user has inserted ?
Can you tell me step by step how you did?
|
|
|
kevind
Posts: 251
|
Posted: 07/10/2013, 6:23 AM |
|
hi azzarev,
I took a quick look at the project and I can't recall what I was trying to do at the time or if I went to another solution.
I found this in an area of the system:
Session("LastProjectID") = CLng(CCDLookUp("last_insert_id()","Project","",DBmySQLconnection))
So I think I was trying to grab the last ID in a project table I have and then use that to add records in related child tables.
My experience in Codecharge is that you'd need to use the above in a form that has a database connection already OR create a connection before inserting actions (Customer SQL) and fetching the last ID.
hope that helps.
_________________
thanks
Kevin
======================
CCS 3.2.x / ASP / MS Access /mySQL / PHP / jQuery / jQuery UI / jQuery Mobile
|
|
|
kevind
Posts: 251
|
Posted: 07/10/2013, 6:24 AM |
|
hi azzarev,
I took a quick look at the project and I can't recall what I was trying to do at the time or if I went to another solution.
I found this in an area of the system:
Session("LastProjectID") = CLng(CCDLookUp("last_insert_id()","Project","",DBmySQLconnection))
So I think I was trying to grab the last ID in a project table I have and then use that to add records in related child platforms.
My experience in Codecharge is that you'd need to use the above in a form that has a database connection already OR create a connection before inserting actions (Customer SQL) and fetching the last ID.
hope that helps.
_________________
thanks
Kevin
======================
CCS 3.2.x / ASP / MS Access /mySQL / PHP / jQuery / jQuery UI / jQuery Mobile
|
|
|