LastInsertedID_SQL

Get the ID of the last inserted record in a table.
There are other methods, need to be tested though


Public

Tested

My Own Work
<%
Function LastInsertedID_SQL(ObjConn, TableName)
' Last Inserted ID
Dim loRs
Set loRs = ObjConn.Execute("SELECT IDENT_CURRENT('" & TableName & "')")
llID = loRs.Fields("NewID").value
LastInsertedID_SQL = llID
' Dim loConn, lsSQL, loRs
' Set loConn = CreateObject("ADODB.Connection")
' loConn.Open(Application("dbConn"))
' Set loRs = ObjConn.Execute("SELECT @@IDENTITY AS NewID;")
' loConn.Close()
' Set loConn = Nothing
' response.write llID
End Function
' Last Insterted ID
' Method 1
' sql = "Select last_insert_id() as mama"
' set recordset = connection.execute(sql)
' NewEvID = cint(recordset("mama"))
' Method 2
' sql = "Select @@IDENTITY as NewId;"
' Set Recordset = connection.execute(Sql)
' NewEvID = Recordset("NewID")
%>
' ===============================================================================
' ===============================================================================

ObjConn, TableName

Views 1456 Downloads 437

Classic ASP Database
ANmarAmdeen
787
Attachments
Revisions

v1.0