Implementation of the code for random record-taking in the recordset under ASP-Application techniques

Source: Internet
Author: User
Code that randomly takes records in a recordset

<%
' Moving to random record-steven Jones ' Extension
If not (recordset name. BOF and recordset name. EOF) Then
' Reset the cursor to the beginning
If (recordset name.) CursorType > 0) Then
The recordset name. MoveFirst
Else
The recordset name. Requery
End If

Recordset name _TOTALRN =-1
Recordset name _TOTALRN = Recordset name. RecordCount ' ony works in some recordsets, but much faster
If (recordset 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
Recordset Name _totalrn=0
While (the not recordset name.) EOF)
Recordset name _TOTALRN = Recordset name _TOTALRN + 1
The recordset name. MoveNext
Wend

' Reset the cursor to the beginning
If (recordset name.) CursorType > 0) Then
The recordset name. MoveFirst
Else
The recordset name. Requery
End If

End If

' Now doing final adjustments, and move to the random
Recordset name _TOTALRN = Recordset name _totalrn-1
IF Recordset name _totalrn > 0 Then
Randomize
The recordset name. Move Int (recordset name _TOTALRN + 1) * Rnd)
End If
End If
' All done; Should always check for a empty recordset before displaying data
%>


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.