Bound controls not updating new DataRow

G

Guest

Using VB.Net, Framework 1.0, Jet 4.0. Two ComboBoxes (prefixed "cbo") and
three DateTimePickers (prefixed "dtp") are bound to a DataSet (m_DS)
populated from four hierarchical tables: Company, which is the parent of
Invoice, which is the parent of both Expense and Timesheet. These are the
bindings:

With cboCompany
.DataSource = m_DS.Tables("Company")
.DisplayMember = "Name"
.ValueMember = "IDNum"
If .DataBindings.Count = 0 Then
.DataBindings.Add("SelectedValue", m_DS, "Company.IDNum")
End If
End With
With cboInvoiceNum
.DataSource = m_DS.Tables("Invoice")
.DisplayMember = "InvoiceNum"
.ValueMember = "IDNum"
If .DataBindings.Count = 0 Then
.DataBindings.Add("SelectedValue", m_DS, "Invoice.IDNum")
End If
End With
With dtpInvoiceDate
If .DataBindings.Count = 0 Then
.DataBindings.Add("Text", m_DS, "Invoice.InvoiceDate")
End If
End With
With dtpFrom
If .DataBindings.Count = 0 Then
.DataBindings.Add("Text", m_DS, "Invoice.FromDate")
End If
End With
With dtpThrough
If .DataBindings.Count = 0 Then
.DataBindings.Add("Text", m_DS, "Invoice.ThroughDate")
End If
End With

A "New" button calls
Me.BindingContext(m_DS, "Invoice").AddNew()
and sets cboInvoiceNum, dtpInvoiceDate, dtpFrom, and dtpThrough.

A "Save" button calls
Dim cm As CurrencyManager = _
CType(Me.BindingContext(m_DS, "Invoice"), CurrencyManager)
cm.EndCurrentEdit()
If Me.m_DS.HasChanges Then
Dim ds As DataSet = Me.m_DS.GetChanges()
If Not ds.HasErrors() Then
Me.m_daInvoice.Update(ds, "Invoice")
Me.m_DS.AcceptChanges()
End If
End If

The new record is inserted in the database, but only the IDNum (an
AutoNumber) and the FromDate columns are populated. Why not the others? Any
help would be greatly appreciated.
 
G

Guest

At the end of the day, I got the DateTimePickers to bind by binding to the
"value" property instead of "text." MS KB and discussion group postings were
helpful in this; thank you. I got the cboCompany to bind by binding it to
the Invoice.CompanyIDNum foreign key. Two lessons learned. However, nothing
I've tried, including Bonnie Berent's suggestion (thank you) that when
binding two ComboBoxes to the same table, you must use two tables, one a copy
of the other, causes cboInvoiceNum to populate the DataSet or be committed to
the database. If anyone has further suggestions, I'd appreciate them.

All the best,
Tom
 

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