Displaying Random Record from Acces Database

liunx

Guest
Ok, someone might see I posted this before... I accidentally did it in the wrong forum (the ASP forum, not the .NET one).

Basically, I'm trying to display random information from an Access Database. The idea is to have a random number generated, then have the information from a record whose number is equal to the randomly generated one.

Now, couple things. I'm an ASP.NET newbie, so I've tended to create all my datasets using Dreamweaver 7's bindings, so if you can manipulate that, it'll make it so much easier for me. If not, well, I'll try my best :D

Also, I'm using ASP.NET VB, so that's a requirement, as well. Annnnd... I have to use an Access Database, because I don't know MySQL.

I know, pretty restrictive, but I've looked for resources on my own, and I simply can't get them to work :(

Any help would be appreciated!I'm beginning to think that this isn't possible with an Access Database =\ I can't find anything that seems to work without using this "NEWID()" thing that will not work with Access.You have a prime key field in ur access database right?
Give this a shot:

1) make a sql stmnt that query the entire prime key
sql = SELECT [your key field] from [your table]

2) do your normal sql thing to get those data out, sqlcommand, sqldatareader, ...etc

3) copy the recordset to a array or something (any collection you are comfortable with at the same time, u can loop through using index...hashtable, arraylist, etc)

4) create a Random number object, range will be from 0 to array.length

5) now, do your sql stmnt again....

sql = "SELECT * FROM [your table] WHERE [primeary id] = @KEYID"
cmd.parameter.add("@KEYID", array(random(your max / min number goes here)))


as you know, i didn't test or debug this "code", but you get the idea how I tackle this problem...

hope that helps
 
Back
Top