I have been working with classic ASP and database access through it. The database im using is MySQL. The ASP pages are running on IIS 7.
I developed two ASP pages. First, here is the schema im working with-
Book = (b_id, title, pages, price, p_id)
Publisher = (p_id, name, country)
p_id in Book is a foreign key from Publisher.
Now, in one script, when adding record in Publisher, i first check whether similar record exists and if it does then report that to user. That script works fine.
But in other script to insert record in Book, i first check whether the specified publisher exists or not. But for some reason, that doesnt work at all. That is, when i query the Publisher table to get all records for comparision, the RecordCount property of the RecordSet object returns -1.
I have checked both scripts extensively for errors and there are none.
Why is the same code for the same purpose not working in one but working in the other ?
The working code –
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
It goes into the loop in the above code.
And the code thats not working –
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
Here, prs.RecordCount returns -1. All variables have been Dim-med in the earlier portion of the code.
Can I offer a different solution that gives you the same result but without using recordcount: