After experiencing a lot of down time, We decided to move this site to
CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.
Fetching Backward Error When Trying to Pick Random Database Entry
|
Author |
Message
|
mcgibbon
-
Total Posts
:
7
- Scores: 0
-
Reward points
:
0
- Joined: 12/3/2009
-
Status: offline
|
Fetching Backward Error When Trying to Pick Random Database Entry
Thursday, December 03, 2009 10:06 AM
( permalink)
I am trying to pick a random entry in a database using asp with vbscript. I keep getting the error: Rowset does not support fetching backward. If anyone has any suggestions on what is wrong with the attached code I would greatly appreciate your input. Thanks, Andy <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!--#include file="../../Connections/connCountriesJET.asp" --> <% Dim rs Dim rs_cmd Dim rs_numRows Set rs_cmd = Server.CreateObject ("ADODB.Command") rs_cmd.ActiveConnection = MM_connCountriesJET_STRING rs_cmd.CommandText = "SELECT ID from countries" rs_cmd.Prepared = true Set rs = rs_cmd.Execute rs_numRows = 0 recCount=rs.RecordCount rs.close set rs=nothing 'Randomize forces the RND() function to use a new sequence of random numbers randomize 'generate the random number based on the record count rec = int(rnd * recCount) Set rs_cmd = Server.CreateObject ("ADODB.Command") rs_cmd.ActiveConnection = MM_connCountriesJET_STRING rs_cmd.CommandText = "SELECT * from countries" rs_cmd.Prepared = true Set rs = rs_cmd.Execute rs_numRows = 0 rs.MoveFirst 'use the Move property of the RecordSet object to move to the random number rs.Move rec %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table> <tr><td><%= rs("Country") %></td></tr> <tr><td><%= rs("Capital") %></td></tr> <tr><td><%= rs("Currency") %></td></tr> <tr><td><%= rs("Population") %></td></tr> <tr><td><%= rs("Language") %></td></tr> <tr><td><%= rs("Religion") %></td></tr> </table> </body> </html> <% rs.Close() Set rs = Nothing %>
|
|
|
|
ebgreen
-
Total Posts
:
8088
- Scores: 95
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Thursday, December 03, 2009 10:32 AM
( permalink)
What if you change the recordset cursortype to 3?
|
|
|
|
mcgibbon
-
Total Posts
:
7
- Scores: 0
-
Reward points
:
0
- Joined: 12/3/2009
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Thursday, December 03, 2009 10:38 AM
( permalink)
Could you explain how to do that and what does that mean exactly? Thanks so much for your help.
|
|
|
|
ebgreen
-
Total Posts
:
8088
- Scores: 95
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Thursday, December 03, 2009 10:50 AM
( permalink)
Set rs = rs_cmd.Execute rs_numRows = 0 rs.CursorType = 3 ' Sets cursor type to adOpenStatic rs.MoveFirst
|
|
|
|
mcgibbon
-
Total Posts
:
7
- Scores: 0
-
Reward points
:
0
- Joined: 12/3/2009
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Thursday, December 03, 2009 11:01 AM
( permalink)
I am now getting the following error: ADODB.Recordset error '800a0e79' Operation is not allowed when the object is open. /RR/_DATA/country_facts_randomizer_test.asp, line 35
|
|
|
|
ebgreen
-
Total Posts
:
8088
- Scores: 95
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Thursday, December 03, 2009 11:17 AM
( permalink)
So create the RS and do the query from an existing RS. As an example: set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT * FROM Customers" rs.CursorLocation = adUseClient rs.CursorType = 3 rs.LockType = adLockBatchOptimistic rs.Open sql, conn
|
|
|
|
mcgibbon
-
Total Posts
:
7
- Scores: 0
-
Reward points
:
0
- Joined: 12/3/2009
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Friday, December 04, 2009 3:52 AM
( permalink)
I am now getting the following error: ADODB.Recordset error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /RR/_DATA/country_facts_randomizer_test.asp, line 34 Here is the code as it exists now: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!--#include file="../../Connections/connCountriesJET.asp" --> <% Dim rs Dim rs_cmd Dim rs_numRows Set rs_cmd = Server.CreateObject ("ADODB.Command") rs_cmd.ActiveConnection = MM_connCountriesJET_STRING rs_cmd.CommandText = "SELECT ID from countries" rs_cmd.Prepared = true Set rs = rs_cmd.Execute rs_numRows = 0 recCount=rs.RecordCount rs.close set rs=nothing 'Randomize forces the RND() function to use a new sequence of random numbers randomize 'generate the random number based on the record count rec = int(rnd * recCount) set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("..\..\..\..\JALCdatabases\countries.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT * FROM Countries" rs.CursorLocation = adUseClient rs.CursorType = 3 rs.LockType = adLockBatchOptimistic rs.Open sql, conn 'use the Move property of the RecordSet object to move to the random number rs.Move rec %>
|
|
|
|
ebgreen
-
Total Posts
:
8088
- Scores: 95
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Friday, December 04, 2009 7:44 AM
( permalink)
Which specific line is 34? Do you ever define the constants anywhere (adUseClient or adLockBatchOptimistic)?
|
|
|
|
mcgibbon
-
Total Posts
:
7
- Scores: 0
-
Reward points
:
0
- Joined: 12/3/2009
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Friday, December 04, 2009 9:50 AM
( permalink)
rs.CursorLocation = adUseClient
|
|
|
|
mcgibbon
-
Total Posts
:
7
- Scores: 0
-
Reward points
:
0
- Joined: 12/3/2009
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Friday, December 04, 2009 9:51 AM
( permalink)
I had not defined them. I tried swapping out the number for each of them. I believe they were all 3 and that didn't help.
|
|
|
|
ebgreen
-
Total Posts
:
8088
- Scores: 95
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Fetching Backward Error When Trying to Pick Random Database Entry
Friday, December 04, 2009 10:08 AM
( permalink)
Put this somewhere near the top: Const adUseClient = 2 Const adLockBatchOptimistic = 4 Const adOpenStatic = 3 Were you putting those others in there just because of the sample code that I showed? If so, I don't know if you need them or not, they were just part of the first clip that I found that showed how to open a query from an existing recordset. Please go to the web and read about these options and understand them and decide for yourself how you need to code it in your situation.
|
|
|
|
Online Bookmarks Sharing: