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