Code for randomly retrieving records in a record set in ASP

Source: Internet
Author: User

Random retrieve records in a record set Code

<%
'Moving to random record-Steven Jones 'Extension
If not (record set name. bof and record set name. EOF) then
'Reset the cursor to the beginning
If (record set name. cursortype> 0) then
Record set name. movefirst
Else
Record set name. requery
End if

Record set name_totalrn =-1
Record set name_totalrn = record set name. recordcount 'ony works on some recordsets, but much faster
If (record set name _ totalrn =-1) then' and if it didn't work, we still have to count the records.

'Count the total records by iterating through the recordset
Record set name _ totalrn = 0
While (not record set name. EOF)
Record set name_totalrn = record set name_totalrn + 1
Record set name. movenext
Wend

'Reset the cursor to the beginning
If (record set name. cursortype> 0) then
Record set name. movefirst
Else
Record set name. requery
End if

End if

'Now do final adjustments, and move to the random record
Record set name_totalrn = record set name_totalrn-1
If record set name_totalrn> 0 then
Randomize
Record set name. Move int (record set name _ totalrn + 1) * RND)
End if
End if
'All done; You shoshould always check for an empty recordset before displaying data
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.