Access random display record Solution

Source: Internet
Author: User
Access random display records (not repeated) solution: I have read a lot of people to discuss the post about access random record retrieval. If not, I wrote a solution for random display records. I hope you can correct it. There are 5 records in the database and 4 records are randomly selected. Code -------------------------------------- % --------------------------- data

Access random display records (not repeated) solution: I have read a lot of people to discuss the post about access random record retrieval. If not, I wrote a solution for random display records. I hope you can correct it. There are 5 records in the database and 4 records are randomly selected. Code -------------------------------------- % '------------------------- data

Access random display records (not repeated) solution:

I have read a lot of posts about random access record retrieval. I have written a solution for random display records. I hope you can correct it. There are 5 records in the database and 4 records are randomly selected.

Code
--------------------------------------

<% '------------------------- Database connection ----------------------- Set objConn = Server. createObject ("ADODB. connection ") objConn. connectionString = "Provider = Microsoft. jet. OLEDB.4.0; "& _" Data Source = "& Server. mapPath ("data. mdb ") objConn. open 'mongodatabase connection ----------------------- '------------------------- retrieve data --------------------- strSQL = "SELECT id, DataColumn FROM able"' SQL statement, retrieve database Set objRS = Server. createObject ("ADODB. recordset ") 'create record set objRS. open strSQL, objConn, 1, 1' execute the search Count = objRS. recordCount 'get record total number Item = 4' display record Count '------------------------- retrieve data ------------------- 'define redim a (Item, 2), t (Count)' defines 2 arrays, array a is used to store records, and array t is used to delete the selected record '-------------------------------' initial array value, objective to compare the data inserted with this value for each j in tj = 0 next '--------------------------------------- 'random extraction Record Number Randomize timer' to initialize the random number generator for j = 1 to Itemk = int (rnd * Count + 1) 'randomly retrieve a record do while t (k) <> 0' from the total number to determine whether the record is already in the array k = int (rnd * Item + 1) loopt (k) = 1 'Next '------------------------------------------------------ j = 1: I = 1 'define subscripts '------------------------------------' some records in the dataset objRS are cyclically selected and stored in the array Do While Not objRS. eofif t (j) = 1 thena (I, 1) = objRS ("id") 'record ida (I, 2) = objRS ("DataColumn ") 'record content I = I + 1 end if j = j + 1 objRS. moveNext Loop '-------------------------------------- 'shanghai' ---------------------------- display content ------------------ for I = 1 to Item Response. write "no." & a (I, 1 )&"
"Response. write" content "& a (I, 2 )&"

"Next '---------------------------- display content ------------------ 'release' release resource objRs. Closeset objRs = nothingobjConn. Closeset objConn = nothing' limit %>



Data

Id DataColumn -------------------------- 1a2b3c4d5e

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.