HasChanges doesn't get "set"

S

Shanon Swafford

I am having problems with the HasChanges() method.

Here's what I have:

1. Access Database with Suppliers and Suppliers_Plants tables.
2. One ComboBox (bound on the Suppliers key) and multiple TextBoxes bound
the Suppliers table fields. This is DataSet41 and I can't seem to see if
there were any changes made.
3. DataGrid bound to the Suppliers_Plants table. This is DataSet121 and
works as expected.

If you change any values (bound to DataSet41 or DataSet121) and hit the
Update button, I want to check if there
are any changes to both/either DataSets and only update them if there are
changes
made.

The updates work but my problems are finding if Dataset41 has been changed.
The only way I can get it to recognize if there are any changes is to make
the change to something besides the key field, then change the ComboBox on
the key to another value then hit my update button.

Here is the code that gets called by the update button:

'This seems only be true if you change the ComboBox to another value.
If DataSet41.HasChanges() Then
Try
Dim tmpDataSet41 As DataSet
tmpDataSet41 = DataSet41.GetChanges(DataRowState.Modified)
OleDbDataAdapter4.Update(tmpDataSet41, "Suppliers")
MessageBox.Show("Suppliers Table updated successfully")
Catch ex As Exception
MessageBox.Show("Can't Update Database" & vbCrLf & ex.Message)
End Try
End If
'This seems to work as expected.
If DataSet121.HasChanges() Then
Try
OleDbDataAdapter12.Update(DataSet121)
MessageBox.Show("Suppliers Refineries Table updated successfully")
Catch ex As Exception
MessageBox.Show("Can't Update Locations Table" & vbCrLf & ex.Message)
End Try
Cursor.Current = System.Windows.Forms.Cursors.Default
End If
'Refresh Data
Try
OleDbSelectCommand12.Parameters.Item("Supplier_Plant_Supplier_ID").Value
& _
= TextBox40.Text
OleDbDataAdapter4.Fill(DataSet41.Suppliers)
OleDbDataAdapter12.Fill(DataSet121.Suppliers_Plants)
Catch ex As Exception
MessageBox.Show("Can't get data" & vbCrLf & ex.Message)
End Try


Am I missing something?

Thanks in advance,
Shanon
 
S

Shanon Swafford

Here's what I have:

1. Access Database with Suppliers and Suppliers_Plants tables.
2. One ComboBox (bound on the Suppliers key) and multiple TextBoxes bound
the Suppliers table fields. This is DataSet41 and I can't seem to see if
there were any changes made.
3. DataGrid bound to the Suppliers_Plants table. This is DataSet121 and
seems to work as expected.

If you change any values (bound to DataSet41 or DataSet121) and hit the
Update button, I want to check if there
are any changes to both/either DataSets and only update them if there are
changes made.

The updates work but my problems are finding if Dataset41 has been changed.
The only way I can get it to recognize if there are any changes is to make
the change to something besides the key field, then change the ComboBox on
the key to another value then hit my update button.

Here is the code that gets called by the update button:

'This seems only be true if you change the ComboBox to another value.
If DataSet41.HasChanges() Then
Try
Dim tmpDataSet41 As DataSet
tmpDataSet41 = DataSet41.GetChanges(DataRowState.Modified)
OleDbDataAdapter4.Update(tmpDataSet41, "Suppliers")
MessageBox.Show("Suppliers Table updated successfully")
Catch ex As Exception
MessageBox.Show("Can't Update Database" & vbCrLf & ex.Message)
End Try
End If
'This seems to work as expected.
If DataSet121.HasChanges() Then
Try
OleDbDataAdapter12.Update(DataSet121)
MessageBox.Show("Suppliers Refineries Table updated successfully")
Catch ex As Exception
MessageBox.Show("Can't Update Locations Table" & vbCrLf & ex.Message)
End Try
Cursor.Current = System.Windows.Forms.Cursors.Default
End If
'Refresh Data
Try
OleDbSelectCommand12.Parameters.Item("Supplier_Plant_Supplier_ID").Va & _
lue = TextBox40.Text
OleDbDataAdapter4.Fill(DataSet41.Suppliers)
OleDbDataAdapter12.Fill(DataSet121.Suppliers_Plants)
Catch ex As Exception
MessageBox.Show("Can't get data" & vbCrLf & ex.Message)
End Try


Am I missing something?

Thanks in advance,
Shanon
 
S

Shanon Swafford

Got it to work now.

Add the following just before the if statement for DataSet41.HasChanges

Me.BindingContext(Me.DataSet41, "Suppliers").EndCurrentEdit()

Is this the best way?

Thanks,
Shanon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top