asp下实现记录集内随机取记录的代码
2018-09-06 12:29
记录集内随机取记录的代码
<%
Movingtorandomrecord-StevenJonesExtension
IfNot(记录集名称.bofand记录集名称.eof)Then
resetthecursortothebeginning
If(记录集名称.CursorType>0)Then
记录集名称.MoveFirst
Else
记录集名称.Requery
EndIf
记录集名称_totalrn=-1
记录集名称_totalrn=记录集名称.RecordCountonyworksonsomerecordsets,butmuchfaster
If(记录集名称_totalrn=-1)Thenandifitdidntwork,westillhavetocounttherecords.
countthetotalrecordsbyiteratingthroughtherecordset
记录集名称_totalrn=0
While(Not记录集名称.EOF)
记录集名称_totalrn=记录集名称_totalrn+1
记录集名称.MoveNext
Wend
resetthecursortothebeginning
If(记录集名称.CursorType>0)Then
记录集名称.MoveFirst
Else
记录集名称.Requery
EndIf
EndIf
nowdofinaladjustments,andmovetotherandomrecord
记录集名称_totalrn=记录集名称_totalrn-1
If记录集名称_totalrn>0Then
Randomize
记录集名称.MoveInt((记录集名称_totalrn+1)*Rnd)
EndIf
EndIf
alldone;youshouldalwayscheckforanemptyrecordsetbeforedisplayingdata
%>