asp 添加记录后立即获得这条记录的ID号

来源:百度知道 编辑:UC知道 时间:2024/06/04 17:30:54
asp 添加记录后立即获得这条记录的ID号
注:SELECT TOP 1 id FROM table ORDER BY id DESC ..
这种方法有时会发生意外,
我这里主要是会员功能,如果用这种方法,同时有N个人添加,在网络时间差上就会出错,

如果是以下这样
rs.addnew
...
rs.update
id=rs("id")
就没问题,但是我现在遇到的问题就是我用这种方法现在获得不了ID啊,获得的为空

在执行添加数据操作后,紧接着执行select @@IDENTITY as [ID],即可获得刚插入的数据的ID。可以搜索一下@@IDENTITY的资料

可以在添加记录的时候创建一个时间锚,也就是注册的时间最好精确到毫秒,并在数据库中存储,然后在根据这个时间锚来查询来获取ID

<%
function htmlencode(str)
dim result
dim l
if isNULL(str) then
htmlencode=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"<"
case ">"
result=result+">"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"""
case "&"
result=result+"&"
case chr(32)
'result=result+" &quo