Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Really simple, and I think rather elegant random record selector!
Old 07-05-2008, 12:31 AM Really simple, and I think rather elegant random record selector!
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I wanted to select some random products from my database for display, a quick look at the web made it look like rocket science! So not to be stopped I came up with this really simple script for doing just that.

Thx for all your help folks and I hope this comes in handy for you.

Code:
 
 
'Turn batch mode on
 
Randomize
 
'Create your recordset
 
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &server.MapPath("/access_db/WebData.mdb")&";" 
Set rs=Server.CreateObject("ADODB.RecordSet")
 
'Setup your cursor and locktype
 
'(If you need explanation of this then I suggest you don't experiment with this code!)
 
rs.CursorType = 3
rs.CursorLocation = 3
rs.LockType = 4
 
'Connect
 
rs.ActiveConnection = conn
rs.open ("Select * from rs")
 
"N" is the number of random records you want to select.
 
For x= 1 to [N]
rs.AbsolutePosition = int(rnd()*rs.RecordCount)
 
'Some code to do something with Record
 
'Delete the used record from the recordset(It isn't deleted from database just marked and inaccessible!)
 
rs.Delete
 
'Get the next random record from the remaining records in the recordset!
 
Next
 
'Cleanup
 
rs.Close
conn.close
Set conn=nothing
Set rs=nothing

Last edited by Sleeping Troll; 07-05-2008 at 02:07 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Really simple, and I think rather elegant random record selector!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52755 seconds with 12 queries