|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Randomize function problem
I'm using a randomize function to display a different featured product, but there are certain items that I want to omit.
Here's the code I'm using: <% Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/theDB.mdb") randomize rdm=int(rnd*15)+246 sql = "SELECT * FROM kbs WHERE kbs.id = " & rdm & " AND kbs.subject NOT IN (20,21)" set rs=conn.execute(sql) %> It's selecting a range of product IDs and it's s'posed to exclude all IDs whose subject is either subjectID 20 or 21. It works fine except when it comes to items with those subjects and then it displays this error message: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. Anyone know a way around this? |
|
#2
|
|||
|
|||
|
that can't be the whole code as none of that would cause the error given. you usually get that error when trying to access a record when the recordset contains no records. a simple check for BOF and EOF can get around that.
__________________
Programmer's Corner |
|
#3
|
|||
|
|||
|
Quote:
Sorry for being a bit thick, but what would I do in such a check? |
|
#4
|
||||
|
||||
|
Code:
If not yourrecordset.eof or yourrecordset.bof then do stuff
__________________
--Dave-- U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM= |
|
#5
|
|||
|
|||
|
That's what I thought, but as I'm quite new to this, thought I'd check.
So I've got this: <% if not rs.eof or rs.bof then %> Page content <% end if %> but I'm still getting the same error message. |
|
#6
|
||||
|
||||
|
Wait, what are you trying to do with your records? You need to show us more of your code. As nopoints said before, what you've shown us will not cause the error you mention.
|
|
#7
|
|||
|
|||
|
Yeah, I was thinking about it last night: what I need to do is either set up a function that randomizes an array of numbers (that doesn't include the IDs of the products I don't want to include) or set up an if statement that randomizes again until it arrives at a non-offending product ID because as the moment I think what is happening is that my query is picking a random number and if that number is one I don't want, it's passing no data on.
|
|
#8
|
|||
|
|||
|
In fact, I used an example that nopoints posted http://forums.devshed.com/t74855/s.html and it did the trick!!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Randomize function problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|