Hi Greg,
Check out this page.
How to Get the Unique ID for the Last Inserted Row
IMO, you should do that all in one transaction. May be write a procedure in mysql that takes all the parameters for Insert and returns the Unique Id. When you do that with 2 recordsets as 2 transactions, you won't be getting the value at all, as it(insert and getting Unique ID) has to be done as a single transaction, which I think you are missing there.
Or construct the SQL string as given below
Code:
strsql = "insert into TABLE_NAME (COL1, Col2) values('You','Me');
strsql = strsql & "select last_insert_id() as NewUniqueId;"
RS.CommandText = strsql
RS.Execute
Response.write RS("NewUniqueId");
Something like this should help you getting that out.
Else you will have to write a procedure that inserts values into table and returns the UniqueId back.
--Create you procedure in MYSQL
Code:
CREATE PROCEDURE InsertVal (IN param1 INT, IN param2 VARCHAR(30))
BEGIN
Insert into TABLENAME(Col1, Col2) Values(param1,param2);
SELECT last_insert_id() as NewUniqueId;
END
'In ASP, your code should be like
Code:
strsql = "Call InsertVal(10,'yourname');"
RS.CommandText = strsql
RS.Execute
Response.write RS("NewUniqueId");
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection