Update Command works erratically

M

mkidd

Hi,

I'm very new at this, guessing I'm missing something simple-- I have an
interface for a "Company" table that consists of a list box where the
Company names appear, then a few text boxes that show the rest of the
Company table info. Then I have "Add" "Update" and "Delete" buttons.

The "Add" and "Delete" Button commands work fine, but when I click on a
company in the list box and change any of its existing textbox fields,
then click "Update", the change is not written to the database (no
error message- nothing happens). BUT, if I make the change, click on
another company name in the list box, then back to the company that I
edited, THEN click Update, the info DOES update to the DB.

I set up an OleDbDataAdapter for the Company table using the Config
wizard. The SQL UPDATE command info that it generated looks ok. I can
post that info if it would help. I'm writing to a MS Access DB.

My Update Button command info is pretty straightforward:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click

Try
daCompany.Update(DsInSales1)
Catch ex As Exception
MsgBox(ex.ToString)
End Try

I'll gladly add any info if it's needed. Thanks in advance.

Mike
 
W

W.G. Ryan eMVP

The devil probably lies in either your control bindings, your datarleations
or lack thereof or the timing. Before you hit Update, do a
Debug.Assert(DsInSales1.HasChanges) // and verify that there are changes to
send. Check your databindings and make sure that each row is finished
editing before prodceeding. If you could post the binding code, it'd be
eqaiser to track down.
 
M

mkidd

Here is the binding code:

Me.lbxCompany2.DataSource = Me.DsInSales1
Me.lbxCompany2.DisplayMember = "Company.CompanyName"
Me.lbxCompany2.ValueMember = "Company.CompanyName"

Me.txtSalesType.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsInSales1,
"Company.SalesCategory"))

Me.cbxSalesRep.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsInSales1,
"Company.InSalesRep"))
Me.cbxSalesRep.DataBindings.Add(New
System.Windows.Forms.Binding("SelectedValue", Me.DsInSales1,
"Company.InSalesRep"))
Me.cbxSalesRep.DataSource = Me.DsInSales1 Me.cbxSalesRep.DisplayMember
= "Reps.InSalesRep"
Me.cbxSalesRep.ValueMember = "Reps.InSalesRep"

Me.txtBusDesc.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.DsInSales1, "Company.BusinessDesc"))

Me.txtAcctNum.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.DsInSales1, "Company.AccountNo"))

I'll try the debug statement. Thanks for your quick reply.

Mike
 

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