Strange Dataset update problem.

K

Kevin Hodgson

I'm experiencing a strange Dataset Update problem with my application.
I have a dataset which has a table holding a set of customer information
records. (address, contact, info, etc.)
I have a series of ComboBoxes (Client Number for selection), and text fields
to show the other data bound to this Dataset.table

If I change a value for the first client in the list, and press my update
client button, the data is successfully updated to the database.
If I change a value for another client (email address, for instance), the
value is not saved back to the database.

In both instances, HasChanges will report true. In the first instance
(changing the first client in the list), the DebugXML shows the row with the
new value.
In the second instance (another client), it shows both the first row, and
the second row (not the row that has actually changed), but neither shows
any changed values, they are all unchanged.
I have included the Subroutine that handles the Update Button click event,
which does the Dataset Update.

The DataAdapter is filled through a stored procedure, and the update command
is also a stored procedure. All parameters are set to the correct source
columns.

This just has me totally baffled, and I hope someone can help me understand
this problem.

Thanks, Kevin

Private Sub btnUpdateClient_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdateClient.Click
Me.connExpress.Open() 'Open the connection
Try

Me.BindingContext(Me.DsCustomerInfo1.CW_customerinfo).EndCurrentEdit()
MsgBox("Has Changes: " & Me.DsCustomerInfo1.HasChanges.ToString)
If Me.DsCustomerInfo1.HasChanges Then
Me.DsCustomerInfo1.GetChanges.WriteXml("c:\test\debug.xml")
End If
Me.daCustomerInfo.Update(Me.DsCustomerInfo1, "CW_customerinfo")
PopulateLicenceInfo()
ClientInfoUpdated = False
ClientInfoUpdate()
Main.AddEventLog(appPermissions.UserID, appSettings.DistributorID,
"6", Me.cmbClientNumber.Tag, "Update Client Data", "",
Me.cmbClientNumber.Text, "", "", "", "")
Me.errUpdatePending.SetError(Me.btnUpdateClient, "")
Me.DsCustomerInfo1.AcceptChanges()
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & vbCrLf & ex.Source.ToString & vbCrLf &
vbCrLf & ex.StackTrace.ToString, MsgBoxStyle.Critical, "SQL Error")
Me.DsCustomerInfo1.RejectChanges()
End Try
Me.connExpress.Close() 'Close the connection
End Sub
 
C

Cor Ligthert

Kevin,

In 80% when this problem is showed is this the solution.

Before the update (or check for changes)
BindingContext(ds.Tables(0)).EndCurrentEdit()

Data is pushed in the datatables after a rowchange (or after this command)

I hope this helps?

Cor
 
K

Kevin Hodgson

Thanks Cor, but I do an EndCurrentEdit already, and check for HasChanges.
If it's the first row, everything works as expected, if it's any other row,
it goes haywire and doesn't work correctly.
 
C

Cor Ligthert

Kevin,

Sorry, I should have seen it. I have been strugled long time myself using a
combobox with a binded textbox.

I have given it up. It is the most buggy control there is in my (and
probably Herfrieds) opinion.
When you can avoid them it is a great control by the way.

I have seen the most strange behaviour with that binded combobox, sent some
samples too this newsgroup and the newsgroup vb.controls. However, never got
one reaction. (Just because nobody knows the answers).

Sorry,

However maybe we see here a solution what is good for me as well.

Cor
 
K

Kevin Hodgson

Yes, I've been having problems with databound ComboBoxes and the Tag
Property not changing to the new selected value until after all events have
been comitted (there doesn't seem to be a way from any ComboBox change event
to get the bound tag value of the new selected item, I always get the tag
value for the previous item). I'm not sure if I'm explaining that well.

For instance, if I have my value member bound to a Client Number, and the
Tag bound to the the Primary Key column (UniqueID), during the change
events, the SelectedValue and Tag are pointing to two different records (The
SelectedValue points to the new row, the tag points to the previously
selected row). After all change events have completed however, the Tag
contains the correct value for the newly selected record.

This is causing me other problems, but I don't think it has a bearing on
this one (at least I hope it doesn't)
 
K

Kevin Hodgson

Hi Cor,

This has gotten even stranger.

Ok, so for an update. If I cycle through more than one client, each client I
"leave" ends up having it's HasChanges property set to true. I suspect this
is due to bound text fields that in the DB are NULL, but since they are
bound to blank TXT Fields, it's getting changed to "" or Nothing, not
DBNull.Value.

Anyway, unless I leave the Client (row), the one I Just changed won't be
updated. However, if I DO leave the Row, my changes will be updated.

I'm at a loss why it works correctly for the first row however. Is there
another Event called when the row is changed by selecting an item in the
ComboBox that I might be missing? All of these controls had their
Databinding set at Design Time.
 
B

Bruce A. Julseth

Cor Ligthert said:
Kevin,

In 80% when this problem is showed is this the solution.

Before the update (or check for changes)
BindingContext(ds.Tables(0)).EndCurrentEdit()

Data is pushed in the datatables after a rowchange (or after this command)

I hope this helps?

Cor

What's the difference between: BindingContext(ds.Tables(0)).EndCurrentEdit()
and (CurrencyManager).EndCurrentEdit(),
and when do one over the other...

Thanks....

Bruce
 
K

Kevin Hodgson

I have solved this problem, though I'm not pleased with how I have to do it.

I am save the currently selected index of the selection combobox, and then
set the selectedindex to -1, and then restore it to the saved selection.
This triggers the Row Change or whatever event is supposed to happen, in the
background, which sets the HasChanges flag correctly. Now all of my updates
are correctly saved. I just need to update my code to pop up the alerter
when actual changes have been made.
 
C

Cor Ligthert

Kevin,

Thanks for letting us know, I stepped out of this one, because I had had
myself to much problems with bounded comboboxes (when not used as
dropdownlist because than I have never a problem).

Cor
 

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