对于access和Sql server 数据库,下面方法可以得到刚刚插入记录的自动编号值。
'得到刚刚插入的记录的自动编号值
dim conn,rs
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider="& Application("conndriver") &";Jet OLEDB:Database Password=;Data Source=" & Server.MapPath("51windows.mdb")
set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from [table] where id is null" '自动编号字段为id
rs.open sql,conn,1,3
rs.addnew
rs("Name") = Request.form("Name")
rs("Name2") = Request.form("Name2")
rs.update
dim NewDbid
NewDbid = rs("id") '得刚刚插入记录的自动编号的值
rs.close
set rs = nothing
conn.close
set conn = nothing
更多方法和其它数据库请参考:How do I get the ID number of a just-inserted record