ASP Javascript (Dreamweaver) insert and retreive Primary Key
--------------------------------------------------------------------------------
Been pulling my hair out all week.
I am working on a registration database, and need to get the last primary key allocated to a insert within the MySQL database. I am trying to use the LAST_INSERT_ID() function to return the value to a session variable.
if (!MM_abortEdit)
{
// execute the insert
var Data, mWedding_ID;
Session("iWedding_ID") = -4;
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.CommandText = "SELECT * FROM " + MM_editTable + ";";
MM_editCmd.Execute();
MM_editCmd.CommandText = "SELECT LAST_INSERT_ID()";
Session("iWedding_ID")=MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();
if (MM_editRedirectUrl)
{
MM_editQuery = MM_editRedirectUrl + "?Wedding_ID=" + Session("iWedding_ID") + "XX";
Response.Write(MM_editQuery);
// Response.Redirect(MM_editRedirectUrl + "?Wedding_ID=" + iWedding_ID);
}
}
With the Unique key, I need to put in into a URL string for the next page. For some reason the execute does not seem to return the value of the LAST_INSERT_ID() function. When I carry this out on the actual Database the right value is returned, but never when I try using the above script...
Does anyone know if .execute actually returns the value returned from the Last_Insert_ID();