我在生成唯一ID时遇到了一些问题,并且还要检查以确保生成的ID不在数据库中。我写了两个简单的函数,但每次运行时,都会出现内存不足错误。
有更好的方法吗?
这是我的代码:
uniqueID = getID()
function getID()
Dim id : id = getUniqueID 'simple random number generator
if checkForID(id) = 0 then
return id
else
id = getID()
end if
end function
function checkForID(id)
SQL="SELECT * FROM userOrderDxTest WHERE orderID =" & id
set rs=Server.CreateObject("ADODB.recordset")
rs.Open SQL,DB,adOpenStatic
if not rs.EOF then
checkForID = 1 'ID already exists
rs.close
set rs = nothing
else
checkForID = 1 'ID doesn't exist
rs.CLOSE
end if
end function
答案 0 :(得分:1)
你总是将checkForID设置为1.它应该是:
if not rs.EOF then
checkForID = 1 'ID already exists
rs.close
set rs = nothing
else
checkForID = 0 'ID doesn't exist