Navigate through a dataset

  • Thread starter Thread starter Guest
  • Start date Start date
Peter Newman napisal(a):
i have a dataset and want to step thrpugh each row each time a user clicks a
button,

and do what?

For each row as new datarow in dataset1.tables(x).rows

next
 
basicly im displaying the data in text boxes, and need to allow the
operators to navigate thro the records
 
You can use a CurrencyManager object and Databinding for navigating and
connecting the data to the textboxes. Here is how you do it:

Dim cmgr as currencyManager '--form level

Private Sub Form_Load(...)
....
cmgr = CType(Me.BindingContext(dataset1.Tables("yourtbl")), CurrencyManager)
cmgr.Position = 0 '--initialize position of currencymanager

'--then bind the textboxes - say you have 5 textboxes
Me.txt1.DataBindings.Add("Text", dataset1.Tables("yourtbl"), "fld1")
Me.txt2.DataBindings.Add("Text", dataset1.Tables("yourtbl"), "fld2")
Me.txt3.DataBindings.Add("Text", dataset1.Tables("yourtbl"), "fld3")
Me.txt4.DataBindings.Add("Text", dataset1.Tables("yourtbl"), "fld4")
Me.txt5.DataBindings.Add("Text", dataset1.Tables("yourtbl"), "fld5")
....
End Sub

Then you can have a button where you increment the currencymanager like this:

Private Sub btn1_Click(...)
cmgr += 1 '--navigate forward
End Sub

Private Sub btn2_Click(...)
cmgr -= 1 '--navigate backward
End Sub

You bind the data from the dataset table to the textboxes. Just make sure
that dataset1.Tables("yourtbl") contains the fields that you specify in the
databinding

'----------------------------------------------------------------field/column name here
Me.txt1.DataBindings.Add("Text", dataset1.Tables("yourtbl"), "fld1")

If the binding isn't working, you can loop through all the columns in your
datatable (dataset1.Tables("yourtbl") ) like this:

For each dc As DataColumn In dataset1.Tables("yourtbl").Columns
Console.Write(dc.ColumnName & ", ")
Next

Look at the output window to see what columns (fields) your datatable
contains. These are the names you have to use in the Databinding of the
textboxes.

HTH
Rich
 
Back
Top