Replies Back to Article
Get ID after insert
Hey
you can download the extension here:
http://www.tom-muck.com/extensions/help/insertretrieve/
I'll be making a flash tutorial for it on my website later this week.
hi i tried that extension but it does not seem to work with MySQL has anyone else got any idea's ?
this works with Microsoft.Jet.OLEDB.4.0
the original dreamweaver insert code:
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
after the MM_editCmd.Execute, insert this new code:
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
Set rsSqlGetIdentity = Server.CreateObject("ADODB.Recordset")
SqlGetIdentity = "Select @@IDENTITY as NewID From myTable"
rsSqlGetIdentity.open SqlGetIdentity,MM_editCmd.ActiveConnection
Session("MySession") = rsSqlGetIdentity("NewID")
rsSqlGetIdentity.close
Set rsSqlGetIdentity = Nothing
MM_editCmd.ActiveConnection.Close
If (Session("MySession") <> "") Then
Response.Redirect("myPage.asp?ID="&Session("MySession"))
End If
I am fairly new to this but looking at line 2 of the bold code, should this not start as rsSqlGetIndentity as opposed to SqlGetIndentity:
rsSqlGetIdentity = "Select @@IDENTITY as NewID From myTable"