经典ASP - 通过SQL访问数据数据的问题

时间:2012-11-28 16:20:19

标签: mysql asp-classic

我一直在使用经典的ASP和数据库访问。我正在使用的数据库是MySQL。 ASP页面正在IIS 7上运行。 我开发了两个ASP页面。首先,这是使用 -

的模式

预订=( b_id ,标题,页数,价格,p_id)

发布商=( p_id ,姓名,国家/地区)

Book中的

p_id是Publisher的外键。

现在,在一个脚本中,当在Publisher中添加记录时,我首先检查是否存在类似记录,如果存在,则将其报告给用户。该脚本工作正常。

但是在Book中插入记录的其他脚本中,我首先检查指定的发布者是否存在。但由于某种原因,这根本不起作用。也就是说,当我查询Publisher表以获取所有记录进行比较时,RecordSet对象的RecordCount属性返回-1。

我已经广泛检查了两个脚本的错误,但没有。

为什么相同目的的相同代码不能在一个工作但在另一个工作?

工作代码 -

flag = false
temprs.Open "select country from publisher where name='" & pubname & "'", conn
if temprs.RecordCount <> 0 then
    do while not temprs.EOF
        if temprs.fields("country") = pubcountry then
            flag = true
            exit do
        end if
        temprs.MoveNext
    loop
end if

它进入上面代码中的循环。

代码不起作用 -

q = "select p_id from publisher where name='" & bookpub & "'"
prs.Open q, conn
pins = false
if prs.RecordCount > 0 then
    pid = prs.fields("p_id")
    pins = true
end if

这里,prs.RecordCount返回-1。所有变量在代码的早期部分都是Dim-med。

1 个答案:

答案 0 :(得分:2)

我可以提供不同的解决方案,但不使用记录计数,而是提供相同的结果:

q = "select p_id from publisher where name='" & bookpub & "'"
prs.Open q, conn
pins = false
if not prs.eof then
    pid = prs("p_id")
    pins = true
end if