Detecting changes in a DataGridView and saving them to the database

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

Hi all

I'm having a problem in my continued experimentations with ADO .Net
and Windows forms.

I've been playing with the Northwind Database on SQL 2005, and with
creating data-bound forms.

I have a form, with a DataGridView called Order_DetailsDataGridView
which was created by dragging and dropping the related table in the
Orders table in the data sources window.

Everything works well until I try to detect and save changes. No
errors, but nothing happens!! When I reload the form, the data is
unchanged.

Here's the code - if anyone can help, I'd be grateful.

Regards
Andrew

Private Sub Order_DetailsDataGridView_CellValueChanged _
(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles Order_DetailsDataGridView.CellValueChanged

Order_DetailsDataGridView.EndEdit()
If Me.NorthwindDataSet.HasChanges Then
Select Case MessageBox.Show("Are you sure you wish to
change this value?", _
"Confirm change", MessageBoxButtons.YesNo)
Case Windows.Forms.DialogResult.Yes
Me.Order_DetailsTableAdapter.Update
(Me.NorthwindDataSet)
End Select
End If
End Sub
 
Andrew can you change your code to this bellow and try it, that case select
looks so strange
If Me.NorthwindDataSet.HasChanges Then
IF MessageBox.Show("Are you sure you wish to change this
value?", _
"Confirm change", MessageBoxButtons.YesNo) =
DialogResult.Yes then
Me.Order_DetailsTableAdapter.Update(Me.NorthwindDataSet)
End if
End If
End Sub

Cor
 
Back
Top