asp下实现记录集内随机取记录的代码
asp下实现记录集内随机取记录的代码
发布时间:2016-12-29 来源:查字典编辑
摘要:记录集内随机取记录的代码0)Then记录集名称.MoveFirstElse记录集名称.RequeryEndIfEndIf'nowdofina...

记录集内随机取记录的代码

<%

'Movingtorandomrecord-StevenJones'Extension

IfNot(记录集名称.bofand记录集名称.eof)Then

'resetthecursortothebeginning

If(记录集名称.CursorType>0)Then

记录集名称.MoveFirst

Else

记录集名称.Requery

EndIf

记录集名称_totalrn=-1

记录集名称_totalrn=记录集名称.RecordCount'onyworksonsomerecordsets,butmuchfaster

If(记录集名称_totalrn=-1)Then'andifitdidn'twork,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

%>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ASP教程学习
热门ASP教程学习
编程开发子分类