Google Answers Logo
View Question
 
Q: Classic ASP and Access 97 : Random records ( No Answer,   1 Comment )
Question  
Subject: Classic ASP and Access 97 : Random records
Category: Computers > Programming
Asked by: terry70-ga
List Price: $5.00
Posted: 24 Mar 2006 19:22 PST
Expires: 23 Apr 2006 20:22 PDT
Question ID: 711672
I need to build an ASP page that will fetch 6 random records from an
Access 97 table each time it's reloaded. I have built the following
query, called qryRandomRecords:

-----
SELECT TOP 6 tblProduit.ProID, tblProduit.ProNom FROM tblProduit ORDER
BY Rnd(ProID);
-----
(ProID is an autonumber field)

This works perfectly within Access; each time I lauch the query, 6
different records are selected.

HOWEVER, the exact same query called from the ASP page ALWAYS return
the same records.

I have tried different variations with no success. I googled this
problem and one theory is that the OLEDB provider caches the seed...

So my question is: how can I achieve my goal? (short of retrieving all
records and jumping to random positions, something i'm reluctant to
do)

My connection string is:

Provider=Microsoft.Jet.OLEDB.4.0; User ID=Admin; Data
Source=c:\data\db.mdb; Mode=Share Deny None; Persist Security
Info=False
Answer  
There is no answer at this time.

Comments  
Subject: Re: Classic ASP and Access 97 : Random records
From: xiuxiu-ga on 29 Mar 2006 02:04 PST
 
<%
dim connstr
dim ojbectConnection
connstr="DBQ="+server.mappath("/db1.mdb")+";DefaultDir=;DRIVER={Microsoft
Access Driver (*.mdb)};"
set ojbectConnection = Server.CreateObject ("ADODB.Connection")
ojbectConnection.Open connstr

dim sql
dim temp
sql="SELECT top 7 * From test;"
set rs=server.createobject("adodb.recordset")
rs.open sql,ojbectConnection,1,1
temp=rs.RecordCount

Do Until temp = 0
	Randomize
	RNumber = Int(Rnd*rs.RecordCount) +1
	temp=temp-1
	'response.Write("<br>")
	if not rs.eof and not rs.bof then
		rs.MoveFirst
		rs.move RNumber
		response.Write rs("id")
	end if
loop

rs.Close()
set rs = nothing
ojbectConnection.close
set ojbectConnection=nothing
%>

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy