Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Select a Random Number from MSAccess Table Using C#

Reply
Thread Tools

Select a Random Number from MSAccess Table Using C#

 
 
dungdang
Guest
Posts: n/a
 
      08-21-2007
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

 
Reply With Quote
 
 
 
 
ca8msm@aspnetlibrary.com
Guest
Posts: n/a
 
      08-21-2007
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;

 
Reply With Quote
 
 
 
 
dungdang
Guest
Posts: n/a
 
      08-21-2007
the On Aug 21, 9:48 am, "(E-Mail Removed)"
<(E-Mail Removed)> 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..

 
Reply With Quote
 
DC
Guest
Posts: n/a
 
      08-22-2007
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,
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help Using list items as output table names in MsACCESS Cathy James Python 0 03-28-2012 09:48 PM
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
to select random number from select list Pranjal Jain Ruby 3 04-10-2008 04:01 PM
How to have C# Web page query MSAccess Database and simultaneously populate MSAccess DB? Siegfried Heintze ASP .Net 1 04-15-2006 11:41 AM



Advertisments