Link to home
Start Free TrialLog in
Avatar of nkewney
nkewneyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Gettting a random field from a DataTable

Dear Experts,

I'm trying to select a random row from a DataSet Table (dsBB).

The table has two columns, Field_ID and Field_Name

I'm generating a random number as follows:

        Dim RandomNumber As Integer
        RandomNumber = Int((dsBB.Tables(0).rows.count - 0 + 1) * Rnd()) + dsBB.Tables(0).rows.count

How can I select a random Field_Name from this DataTable and return it as a string?

Any help would be appreciated

Thanks

Nick
Avatar of vbturbo
vbturbo
Flag of Denmark image

Hi

You would create a random number that are <= the tables row count

Then pick the generated row number and what random generator has generated for you.
Then represent Field_Name from the select.

Cheers

vbturbo
Avatar of nkewney

ASKER

Thanks for that - could you give me an example if you get a minute?

Thanks

Nick
ASKER CERTIFIED SOLUTION
Avatar of vbturbo
vbturbo
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nkewney

ASKER

Absolutely spot on - thanks so much vbturbo:

Nick