Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop through dataset and change each value 1

Status
Not open for further replies.

NSNewey

Programmer
Jun 29, 2005
125
GB
Hi

I have a windows form showing a customer enquiry.
There is a DGV showing each entry for this enquiry.
When the user deletes an entry, I need to loop through each record in the entry table and renumber the "itemNumber" field so they remain consecutive.

The item number field is not displayed in the DGV.

I have successfully done this using a data reader to iterate each record and update each item number value using an oleDbCommand Update.

I know there is a better way to do this as the form has the enquiry entry table adapter in it.

What’s the best way to edit a field in each line in the table…

Something like…

Code:
For each row in the table
	Edit the item number field
Next

Thanks

Neil
 
Is your DataGridView bound to a DataSet/DataTable?

Try the following:

Code:
Dim RunningTotal As Integer = 0
For Each dr As DataRow In YourDataTable.Rows
  dr.Item("YourColumnName") = RunningTotal
  RunningTotal += 1 
Next
 
Hi RiverGuy

Yes the dgv is bound to a tableAdapter

I have tried your code which runs fine but does not update the table.

As a test, I tried this to see if it would set every entry record's itemNo field in the dgv to 5...

Code:
For Each dr As DataRow In Me.TradeBaseDataSet.tJobEntry.Rows
      dr.Item("itemNo") = 5
Next

There is no error but when I select a line in the dgv and open that record, the itemNo field has not changed.

Am i missing an update or acceptChanges somewhere.

I know this is a newby question but I am fairly new to vb.net.
 
Update...

I added this...

Me.TJobEntryTableAdapter.Update(Me.TradeBaseDataSet.tJobEntry)

and now it works.

Thanks for pointing me in the right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top