Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp classic 随机数与数据库检查_Asp Classic - Fatal编程技术网

Asp classic 随机数与数据库检查

Asp classic 随机数与数据库检查,asp-classic,Asp Classic,我在生成一个唯一的ID时遇到了一些问题,并且正在检查以确保生成的ID不在数据库中。我编写了两个简单的函数,但每次运行时,都会出现内存不足错误 有更好的方法吗 这是我的密码: uniqueID = getID() function getID() Dim id : id = getUniqueID 'simple random number generator if checkForID(id) = 0 then return id else id

我在生成一个唯一的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

您总是将checkForID设置为1。应该是:

if not rs.EOF then
    checkForID = 1   'ID already exists
    rs.close
    set rs = nothing
else
    checkForID = 0    'ID doesn't exist