Select a Random Number from MSAccess Table Using C#

D

dungdang

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
 
C

ca8msm

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;
 
D

dungdang

the On Aug 21, 9:48 am, "(e-mail address removed)"
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..
 
D

DC

dungdang said:
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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top