№§:获取数据库里最新的种子值!
第一种方法:@@IDENTITY
特点:支持sql Server 和ACCESS
'
隐式调用Command对象
sql = " INSERT INTO admin_user (a_user) VALUES ('aaa') "
Conn.Execute(sql)
sql = " select @@identity AS ID "
' sql = "Select IDENT_CURRENT(admin_user) AS ID" 'access 不支持
Set rs = Conn.ExeCute(sql)
Response.Write(rs( 0 ))
' 显示调用Command对象
sql = " INSERT INTO admin_user (a_user) VALUES ('aaa') "
Conn.Execute(sql)
Set comm = Server.CreateObject( " adodb.command " )
comm.CommandText = " select @@identity "
comm.ActiveConnection = conn
Set rs = comm.Execute()
Response.Write(rs( 0 ))
sql = " INSERT INTO admin_user (a_user) VALUES ('aaa') "
Conn.Execute(sql)
sql = " select @@identity AS ID "
' sql = "Select IDENT_CURRENT(admin_user) AS ID" 'access 不支持
Set rs = Conn.ExeCute(sql)
Response.Write(rs( 0 ))
' 显示调用Command对象
sql = " INSERT INTO admin_user (a_user) VALUES ('aaa') "
Conn.Execute(sql)
Set comm = Server.CreateObject( " adodb.command " )
comm.CommandText = " select @@identity "
comm.ActiveConnection = conn
Set rs = comm.Execute()
Response.Write(rs( 0 ))
第二种方法:IDENT_CURRENT(table_name)
第三种方法:SCOPE_IDENTITY ()
而第一种方法要求,必须用Jet引擎打开数据库连接。
后两种方法,不能使用在ACCESS中,它们是sql的内置函数。