Replies Back to Article

Get ID after insert

here it is
August 23, 2005 by Aron K

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.

does not work
August 27, 2005 by sdsaddsa asdsadd

 

hi i tried that extension but it does not seem to work with MySQL has anyone else got any idea's ?

did yo uever get an answer?
October 5, 2005 by Matt Bristow
Did you ever get this to work? I use Georges extension with MS SQL all the time and its fantastic but with MYSQL it doesn't want to know
Get ID after insert
April 5, 2006 by t pinorama2012

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

Code mistake??
September 25, 2006 by David Tregoning

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"

opps
September 25, 2006 by David Tregoning
said I was new to this - ignore my last comment