473,395 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Disconected Recordset & Random Selection

Hello All,

How would I go about using a disconnect recordset and select (x) records
from it, x being the number of records to be selected.

Many thanks in advance.

--
Andie

Remove TRASH from email address to reply
Jul 19 '05 #1
3 3208
Basically within my database, I have a table called products, and I was told
about using a client side or "disconnected recordset" to display records on
the asp page I am using, I currently use an array to store all the product
information to be displayed, and then randomly display 6 products on the
screen.

How would I used a client side recordset to display 6 different records each
time?

Soeey but you will have to bear with me as I am only just getting to grips
with ASP programming..

Many thanks in advance.

--
Andie

Remove TRASH from email address to reply
"Tim Williams" <saxifrax@pacbell*dot*net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
You cannot "select..." from a standalone recordset, but you can sort/filter it.
You don't say which records you want to retrieve, so difficult to give any
more details than that.

tim
"Andie" <an***@mansunTRASH.freeserve.co.uk> wrote in message
news:Q9*********************@wards.force9.net...
Hello All,

How would I go about using a disconnect recordset and select (x) records
from it, x being the number of records to be selected.

Many thanks in advance.

--
Andie

Remove TRASH from email address to reply


Jul 19 '05 #2
You don't need a disconnected recordset just to display records - they are
only really useful if you want to persist the data between calls/pages.

Selecting "random" records from a database is not so straightforward: try
this or a variant of it -
http://www.aspfaq.com/show.asp?id=2132

Exactly how you do it may depend on how many records you have in your DB
table...
A search on Google for "asp random records" should get you some ideas.
tim

"Andie" <an***@mansunTRASH.freeserve.co.uk> wrote in message
news:h6*********************@wards.force9.net...
Basically within my database, I have a table called products, and I was told about using a client side or "disconnected recordset" to display records on the asp page I am using, I currently use an array to store all the product
information to be displayed, and then randomly display 6 products on the
screen.

How would I used a client side recordset to display 6 different records each time?

Soeey but you will have to bear with me as I am only just getting to grips
with ASP programming..

Many thanks in advance.

--
Andie

Remove TRASH from email address to reply
"Tim Williams" <saxifrax@pacbell*dot*net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
You cannot "select..." from a standalone recordset, but you can

sort/filter
it.
You don't say which records you want to retrieve, so difficult to give any more details than that.

tim
"Andie" <an***@mansunTRASH.freeserve.co.uk> wrote in message
news:Q9*********************@wards.force9.net...
Hello All,

How would I go about using a disconnect recordset and select (x) records from it, x being the number of records to be selected.

Many thanks in advance.

--
Andie

Remove TRASH from email address to reply



Jul 19 '05 #3
Depending on your backend database, it will almost always be more efficient
to do this via your original query (see Tim's link).

I do not believe that using a disconnected recordset will help here. For one
thing, you cannot add a field to a recordset that has been opened on a data
source, disconnected or otherwise.

Since I don't know what your database is, let me show a variation of the
alternate technique shown in Tim's link that may be more efficient (untested
air code):

dim cn, rs, strSQL,ar, arSelected(5), rCount, CurrRR, SelectedCount, i,j
'open a recordset using the default firehose cursor
strSQL = "Select idProduct FROM products"
set rs=cn.execute(strSQL,,&H0001)
ar=rs.getrows
rs.close
rCount = ubound(ar,2)
SelectedCount = 0
do until SelectedCount = 6
randomize
CurrRR = cLng(rnd*rCount+0.5)
if not AlreadySelected(arSelected, CurrRR) then
arSelected(SelectedCount) = CurrRR
SelectedCount = SelectedCount + 1
end if
loop

strSQL="Select idProduct, description, descriptionLong " & _
"listPrice, price, smallImageUrl, stock, fileName, noShipCharge " & _
"FROM products WHERE idProduct IN ("
for i = 0 to 5
if i = 0 then
strSQL = strSQL & ar(0,i)
else
strSQL = strSQL & "," & ar(0,i)
end if
next
strSQL = strSQL & ")"
response.write strSQL 'for debugging only
set rs=cn.execute(strSQL,,&H0001)
ar=rs.getrows
rs.close
set rs=nothing
cn.close
set cn=nothing

response.write "<table>"
for i = 0 to 5
response.write "<tr>"
for j = 0 to ubound(ar,1)
response.write "<td>"
response.write ar(j, i)
response.write "</td>"
next
response.write "</tr>"
next
response.write "</table>"

Function AlreadySelected(pAr, pSelected)
dim i
AlreadySelected = false
for i = 0 to ubound(pAr)
if len(pAr(i)) = 0 then
exit for
if pAr(i) = pSelected then
AlreadySelected = true
exit for
end if
next

Andie wrote:
OK,

Sorry to sound a little slow, I am still learning this stuff.

I have been told I need to do the following steps to display random
products from the product table within my database.

1) get recordset of fetured items,
(2) disconnect,
(3) Add a field and populate with random integers,
(4) sort by the random field,
(5) display first x number of records.

The fields I need to to retrieve from the products table are:

idProduct
description
descriptionLong
listPrice
price
smallImageUrl
stock
fileName
noShipCharge

I hope this helps you understand what I am trying to do but I was
told that using a disconnected recordset works quicker than using the
array method I am currently using.

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bart Nessux | last post by:
I am using method 'a' below to pick 25 names from a pool of 225. A co-worker is using method 'b' by running it 25 times and throwing out the winning name (names are associated with numbers) after...
1
by: Micak | last post by:
I'm using radnom selection in ms access to select certain number of questions for the exam. i have two versions of the report: - one without marked answers - one with marked answers the problem...
2
by: Lyn | last post by:
If I have a form where the RecordSource property is set to the name of a table, then on opening the SingleForm form I can cycle through all the records in the table one at a time via Next and...
3
by: Wance | last post by:
Hi everybody, I have datatable and stored in dataset. The dataset Never connect to datasource before. How can I move mydata in dataset into the table in data souce? For instance my table say it ...
5
by: jordi | last post by:
I need the random.sample functionality where the population grows up to long int items. Do you know how could I get this same functionality in another way? thanks in advance. Jordi
19
by: Boris Borcic | last post by:
does x.sort(cmp = lambda x,y : cmp(random.random(),0.5)) pick a random shuffle of x with uniform distribution ? Intuitively, assuming list.sort() does a minimal number of comparisons to ...
10
by: Immortalist | last post by:
Various aquisition devices that guide learning along particular pathways towards human biases. And as E.O. Wilson might say mental development appears to be genetically constrained. (1) Language...
1
by: KMEscherich | last post by:
Platform = Windows Program = Access 2003 Hi there, I am stumpped!! I am attempting to populate a form control as follows: I have a form that has 2 drop-down boxes. One retrieves the...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.