cycle through records in dataset

jonathen

Member
Joined
May 12, 2005
Messages
17
Programming Experience
1-3
Hi Guys,

Another query! I have a windows form that has a dataset in it which has been populated from a stored procedure (using enterprise library). This dataset simply has several hundred rows. What I would like to do is, when pressing my "start" button, beging cycling through the records in that dataset (randomly), then when the "pause" button is pressed, pause at the current record and then display it.

Finally, when the "resume" button is pressed, the cycling through records continues, but from the record it paused at.

Is all this possible and feasible?

Thanks.

Jon
 
First off, there are no records in a DataSet. A DataSet contains DataTables and the DataTables contain DataRows. Each DataRow represents an individual record.

What do you mean by cycling through the records randomly? Are you intending to display a random record for a period of time then move to the next random record, or do you just mean that this cycling will be going on behind the scenes until the user presses the Pause button? If it's the latter then any "cycling" is pointless. Simply select a random record when the user presses the button. If you are intending to update a displayed record continually until the button is pressed then you'll need to use a Timer to control that. Either way you're going to need to use a Random object to generate an index, which you then use to retrieve the corresponding row. I think you need to be a bit more specific about what you're trying to achieve.
 
No worries - I figured it out in the end by using the following:

Randomize()
Dim i As Integer = 0
Dim oRow As DataRow
Dim iRowCount As Integer = oTbl.Rows.Count

i = CInt(Rnd() * iRowCount) + 1
oRow = oTbl.Rows(i)

Thanks for your help.
 
jonathen said:
No worries - I figured it out in the end by using the following:

Randomize()
Dim i As Integer = 0
Dim oRow As DataRow
Dim iRowCount As Integer = oTbl.Rows.Count

i = CInt(Rnd() * iRowCount) + 1
oRow = oTbl.Rows(i)

Thanks for your help.
Nooooooooo! ;) As I said, use a Random object. The Randomize and Rnd methods are hold-overs from VB6. Use the Random class, e.g.
VB.NET:
Dim myRandom As New Random
Dim myDataRow As DataRow = myTable.Rows(myRandom.Next(0, myTable.Rows.Count))
 
Back
Top