ASP code enables access to randomly display a record without duplicates

Source: Internet
Author: User

Www.veryhuo.com]

<%


'-------------------------database connection-----------------------


Set objconn = Server.CreateObject ("ADODB. Connection ")


objconn.connectionstring = "provider=microsoft.jet.oledb.4.0;" &_


"Data source=" & Server.MapPath ("Data.mdb")


objConn.Open


'-------------------------database connection-----------------------


'-------------------------retrieving data-----------------------


strSQL = "Select Id,datacolumn from DataTable"


' SQL statement, retrieving database


Set objRS = Server.CreateObject ("ADODB. Recordset ")


' Create recordset


Objrs.open strSQL, objconn, 1, 1


' Perform search


Count=objrs.recordcount


' Gets the total number of records


Item=4


' shows the number of records


'-------------------------retrieving data-----------------------


'------------------------------------------------------------------------------- 


ReDim A (Item, 2), T (Count)


' defines 2 arrays, array A is used to store records, and array t is used to delete records


'--------------------------------------- 


' initial array value, intended to be compared with this value after inserting data


for all J in T


j=0


Next


'--------------------------------------- 


'--------------------------------------- 


' Random decimation record number


Randomize Timer ' initialize random number generator


for J=1 to Item


k=int (rnd*count+1) ' randomly takes a record from the total


Do While t (k) <>0 ' determines whether the record is already in the array


k=int (rnd*item+1)


Loop


T (k) =1 ' K Records selected


Next


'-------------------------------------- 


j=1:i=1 ' define subscript


'-------------------------------------- 


' objRS Some of the records in the "loop-select DataSet" into an array


do, not objrs.eof


if T (j) =1 then


A (i,1) =objrs ("id") ' Record ID


A (i,2) =objrs ("DataColumn") ' record content


i=i+1


End If


j=j+1


Objrs.movenext


Loop


'-------------------------------------- 


'------------------------------------------------------------------------------- 


'----------------------------display content--------------------


for I=1 to Item


Response.Write "Serial number" &a (i,1) & "<br>"


Response.Write "Content" &a (i,2) & "<p>"


Next


'----------------------------display content--------------------


'--------------------------- 


' Release Resources


Objrs.close


Set objrs=nothing


Objconn.close


Set objconn=nothing


'--------------------------- 


%>
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.