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("iWeddi ng_ID") = -4;
var MM_editCmd = Server.CreateOb ject('ADODB.Com mand');
MM_editCmd.Acti veConnection = MM_editConnecti on;
MM_editCmd.Comm andText = MM_editQuery;
MM_editCmd.Exec ute();
MM_editCmd.Comm andText = "SELECT * FROM " + MM_editTable + ";";
MM_editCmd.Exec ute();
MM_editCmd.Comm andText = "SELECT LAST_INSERT_ID( )";
Session("iWeddi ng_ID")=MM_edit Cmd.Execute();
MM_editCmd.Acti veConnection.Cl ose();
if (MM_editRedirec tUrl)
{
MM_editQuery = MM_editRedirect Url + "?Wedding_I D=" + Session("iWeddi ng_ID") + "XX";
Response.Write( MM_editQuery);
// Response.Redire ct(MM_editRedir ectUrl + "?Wedding_I D=" + 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( );
--------------------------------------------------------------------------------
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("iWeddi ng_ID") = -4;
var MM_editCmd = Server.CreateOb ject('ADODB.Com mand');
MM_editCmd.Acti veConnection = MM_editConnecti on;
MM_editCmd.Comm andText = MM_editQuery;
MM_editCmd.Exec ute();
MM_editCmd.Comm andText = "SELECT * FROM " + MM_editTable + ";";
MM_editCmd.Exec ute();
MM_editCmd.Comm andText = "SELECT LAST_INSERT_ID( )";
Session("iWeddi ng_ID")=MM_edit Cmd.Execute();
MM_editCmd.Acti veConnection.Cl ose();
if (MM_editRedirec tUrl)
{
MM_editQuery = MM_editRedirect Url + "?Wedding_I D=" + Session("iWeddi ng_ID") + "XX";
Response.Write( MM_editQuery);
// Response.Redire ct(MM_editRedir ectUrl + "?Wedding_I D=" + 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( );
Comment