Select a Random Number from MSAccess Table Using C#

Discussion in 'ASP .Net' started by dungdang, Aug 21, 2007.

  1. dungdang

    dungdang Guest

    Hello,
    I want to use C# to select a random number from MS Access database
    table.
    <SELECT TOP 1 userID FROM users ORDER BY NEWID()> seem to work only
    with SQL Server.

    dungdang
     
    dungdang, Aug 21, 2007
    #1
    1. Advertising

  2. dungdang

    Guest

    You may be better off asking directly in an Access group, however, you
    could do this directly in your Access query by using the RND function
    in conjunction with a calculation on a field e.g.

    SELECT TOP 1 Rnd(Len([LastName])) AS Expr1, LastName
    FROM Employees
    ORDER BY Rnd(Len([LastName])) DESC;
     
    , Aug 21, 2007
    #2
    1. Advertising

  3. dungdang

    dungdang Guest

    the On Aug 21, 9:48 am, ""
    <> wrote:
    > You may be better off asking directly in an Access group, however, you
    > could do this directly in your Access query by using the RND function
    > in conjunction with a calculation on a field e.g.
    >
    > SELECT TOP 1 Rnd(Len([LastName])) AS Expr1, LastName
    > FROM Employees
    > ORDER BY Rnd(Len([LastName])) DESC;



    I've this method also, on the Access it works fine..but on C# code
    (WinForm), it keeps constatntly picking the same number again and
    again..
     
    dungdang, Aug 21, 2007
    #3
  4. dungdang

    DC Guest

    dungdang wrote:
    > Hello,
    > I want to use C# to select a random number from MS Access database
    > table.
    > <SELECT TOP 1 userID FROM users ORDER BY NEWID()> seem to work only
    > with SQL Server.
    >
    > dungdang
    >


    Do you use the "randomise" function befor using RND? if not then you
    will always get the same "random" number as you are not getting the
    clock to seed the RND function.

    Luck,
     
    DC, Aug 22, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siegfried Heintze
    Replies:
    1
    Views:
    796
    Paul Henderson
    Apr 15, 2006
  2. globalrev
    Replies:
    4
    Views:
    814
    Gabriel Genellina
    Apr 20, 2008
  3. Pranjal Jain
    Replies:
    3
    Views:
    183
    saras
    Apr 10, 2008
  4. VK
    Replies:
    15
    Views:
    1,323
    Dr J R Stockton
    May 2, 2010
  5. Cathy James
    Replies:
    0
    Views:
    308
    Cathy James
    Mar 28, 2012
Loading...

Share This Page