GetChanges returns nothing after data in bound control is changed

D

diesel

I've got a DataTable called dtOrders that is populated with orders from
an Access table. There is an associated DataView called dvOrders, which
stores a single record (the current order). I have several text fields
bound to this DataView, as follows:

Dim bindOrderID As Binding
txtOrderID.DataBindings.Clear()
bindOrderID = New Binding("Text", dvOrders, "order_id")
txtOrderID.DataBindings.Add(bindOrderID)

Dim bindOrderSKU As Binding
txtOrderSKU.DataBindings.Clear()
bindOrderSKU = New Binding("Text", dvOrders, "sku")
txtOrderSKU.DataBindings.Add(bindOrderSKU)

Dim bindPaymentsDate As Binding
txtPaymentDate.DataBindings.Clear()
bindPaymentsDate = New Binding("Text", dvOrders, "payments_date")
txtPaymentDate.DataBindings.Add(bindPaymentsDate)

Etc...

There is a save button that the user can click to save changes to an
order to the db. The problem is that when the user makes changes and
clicks Save, the DataTable isn't seeing the changes.

This is the code that runs when the user clicks save:

Dim da1 As New OleDbDataAdapter
BindingContext(dtOrders.DataSet).EndCurrentEdit()
If Not dtOrders.GetChanges Is Nothing Then
da1.Update(dtOrders)
End If

It never gets to the Update, because the changes never seem to
register. I've tried changing the focus, moving to another record,
etc. but nothing seems to convince the DataTable that changes have been
made.

Any help would be appreciated.
 
M

Miha Markic [MVP C#]

Hi diesel,

You are picking incorrect CurrencyManager. You should use the same
parameters as used for binding:
BindingContext(dvOrders).EndCurrentEdit()

It matters. If you pass other parameters (like you did) the bindingcontext
silently creates a new instance of currency manager for you.
So, you might also check beforehand if your CurrencyManager exists:
if BindingContext.Contains(dvOrders) ....
 
D

diesel

Miha,

You rock. That's all it was. It works fine now. I guess I need to
learn more about how the CurrencyManager works....

Thanks a lot!
 

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