Disconected Recordset & Random Selection

Ask a Question related to ASP, Design and Development.

  1. #1

    Default 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


    Andie Guest

  2. Similar Questions and Discussions

    1. Random selection
      Hi You can use "select distinct names from table_name order by rand() limit 3". Hope this helps and let me know. cheers Binay -----...
    2. clear chat history when disconected
      hi, im new to flash media server, im creating a chat room using the components provided in the sample_lobby file, i have two questions: 1.- how...
    3. Random frame selection?
      I have just started using Director, so this is probably a simple/stupid question. Anyway, I am doing a short story in which the user can interact...
    4. Random Button Selection
      I am creating a CDROM presentation using Director MX (Mac/PC delivery). This presentation has a couple of sections that have a number of buttons that...
    5. Random image in a random place.
      Anyone know javascript? I have a grid(4 x 4) of 16 spacer images and a few text links on the side. Each text link represents a different folder of...
  3. #2

    Default Re: Disconected Recordset & Random Selection

    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:%23XfJwb0QDHA.1564@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" <andie@mansunTRASH.freeserve.co.uk> wrote in message
    > news:Q9INa.45817$9C6.2267430@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
    > >
    > >
    >
    >

    Andie Guest

  4. #3

    Default Re: Disconected Recordset & Random Selection

    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 -
    [url]http://www.aspfaq.com/show.asp?id=2132[/url]

    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" <andie@mansunTRASH.freeserve.co.uk> wrote in message
    news:h6jOa.46138$9C6.2315936@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:%23XfJwb0QDHA.1564@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" <andie@mansunTRASH.freeserve.co.uk> wrote in message
    > > news:Q9INa.45817$9C6.2267430@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
    > > >
    > > >
    > >
    > >
    >
    >

    Tim Williams Guest

  5. #4

    Default Re: Disconected Recordset & Random Selection

    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.

    Bob Barrows Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139