...

View Full Version : Error with empty recordset



paulafernandes
02-12-2003, 01:27 PM
Hi! Here am I again...

I have to do an ASP page that must have 8 combobox.
I'm doing this way:
I do a query to my database (SQL Server 7.0) and store it in a recordset. Then I create a combobox and I display the first result, then I do "objrecordset.movenext", create a second combobox and put on it the second result and so on...
The problem is that, for example, I have 3 results of the query, and when I create the 4 combobox and I do the "objrecordset.movenext" it gives me the "Either BOF or EOF is True.." error.
I'm doing:
if (objrecordset.EOF) then
Response.Write "Empty"
else
objrecordset.MoveNext
Response.Write objrecordset("doc")
end if

but I still get that error.

What am I doing wrong????

Paula

head8k
02-12-2003, 02:14 PM
First thing to do is think if this really is the best way you can accomplish what you are trying to do. If you need 8 comboboxes on your page yet there is a chance that your script will error I would say it is badly designed in the first place.

Having said that if there really is no other way, you can check the length of the recordset providing you open it using a non forward-only cursor. By default, when you open a recordset it uses a forward only cursor but you need one that lets you move backwards and forwards (a dynamic cursor) in order to check the length of the recordset.

When I iterate through a recordset I usually do something like this, maybe it will help you...

If objRS.EOF Then
' there was an error - nothing in the recordset
Else
Do While Not objRS.EOF
' more code here
objRS.MoveNext
Loop
End If

arnyinc
02-13-2003, 02:41 PM
I don't fully understand what your problem is, but looking at your code, it appears those two lines will cause the error you are receiving. You check to see if your recordset is EOF. If it isn't then you move to the next record before printing out a value.

If you happen to be on the last record, then use objrecordset.movenext to go to the next record before using response.write to print the value, that should cause your error.



if (objrecordset.EOF) then
Response.Write "Empty"
else
objrecordset.MoveNext 'switch these two lines
Response.Write objrecordset("doc") 'switch these two lines
end if



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum