I am trying to read through a table and for each row execute a few lines of code.
(The lines of code are taking an data type integer column which contains a time HHMM and a data type datetime column which contains a date.
The code combines the time into the date column since they should have both been in a datetime column to begin with.)
I created a Windows Forms Application project.
In that project I created a Dataset containing the table.
I dragged the table to the form creating a DataGridView.
I added a button.
In the buttons Click event I added the forllowing code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ServedDateTime As DateTime For Each row As DataRow In Chelan400DataSet.Tables("Sheriff_Civil_Master").Rows Dim timeServed As Integer = CInt(row(21)) Dim TS As New TimeSpan(timeServed \ 100, timeServed Mod 100, 0) ServedDateTime = Convert.ToDateTime(row(39)) + TS row(39) = ServedDateTime Next End Sub
When I click the button the code runs and updates the date column in the datagridview as I intended.
I then click the save button on the binding navagator toolbar to save the changes to the table.
Private Sub Sheriff_Civil_MasterBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sheriff_Civil_MasterBindingNavigatorSaveItem.Click Me.Validate() Me.Sheriff_Civil_MasterBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.Chelan400DataSet) End Sub
The changes disappear from the Datagridview and don't update the table.
If I type a change directly into the datagridview instead of using code to make the changes, then click the save button on the navagator toolbar, the changes still appear in the datagridview and update the table.
I don't understand why the changes made with code will show in the DGV but disappear when the saved button is clicked but changes typed into the DGV will be saved when the save button is clicked.
Any and all help is very much appreciated.