Problem with Randomly Selecting a Row

Results 1 to 2 of 2

Thread: Problem with Randomly Selecting a Row

  1. #1
    Join Date
    Dec 1969

    Default Problem with Randomly Selecting a Row

    I am looking for a way to randomly select a row from a database. I am using Microsoft Access to create new tables. I am programming with .NET software in C#. (I am not using SQL Server). I&#039;ve tried:<BR>"SELECT * FROM TABLE1 ORDER BY RAND();"<BR>which does not work. Any information on the subject at all would be greatly appreciated. Thank You.<BR> John Paul

  2. #2
    Join Date
    Dec 1969

    Default If you have an autonumber field...

    ...and there are no gaps in the numbering of your records (that is, you only ever add records, never delete them), then it&#039;s trivial:<BR><BR>You do a query to get the Max(id) and then do a second query to pick a random id between 1 and that value.<BR><BR>There are other ideas in the ASPFAQs (link at top right corner of this very page!). They were designed for use with ASP, not ASP.Net, but you should be able to adapt at least one or two of them for C#.Net.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts