Bound Dataset not reflecting changes

  • Thread starter Thread starter Shane Brodie
  • Start date Start date
S

Shane Brodie

I'm new to .Net, but have 8+ years using VB. I'm having a problem using
data binding in a windows Forms project.

The scenario:

I have a simple form with a series of text boxes and associated labels for
containing input which all goes into the same table. In addition there is a
ComboBox control.

I have 2 data adapters and 2 datasets. One data adapter dataset pair is
bound to a single table and all text boxes are bound to the desired fields
in the dataset. The second dataset is bound to the listbox and is used only
to provide a lookup table (In this case a listing of states and provinces).
The SelectedValue property is also bound to dataset1.

The form displays fine, the listbox populates fine. Any entries made into
the textboxes on the form appear to be ignored. Following is the code from
the cmdOkay button:

dsCompany.GetChanges()

If dsCompany.HasChanges Then

Try

'according to any examples I have found, I need only execute the
following 3 statements

'bata-binding is supposed to be a 2-way process

Me.sqlCN.Open()

Me.daDealerCompany.Update(dsCompany, "tblDealerCompany")

Me.sqlCN.Close()

Catch adoEx As OleDb.OleDbException

Dim strMessage As String

strMessage = "ADO Error: " & adoEx.ErrorCode & vbCrLf & _

adoEx.Message

MsgBox(strMessage)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End If

Me.Hide()



Any help is greatly appreciated.



Shane Brodie
 
Excuse any confusion with the occurences of "ListBox" in my message. I
should have typed ComboBox. It's been a long week ...
 
Found the solution to my own problem:

The table in question is empty when the application is first launched. When
I initialize my form I now check for the count of rows in my table by
checking the BindingManagerBase.Count assiciated with my dataset. If the
count is 0, I call the AddNew method of my BindingManagerBase instance.
Example:

bmb = Me.BindingContext(dsCompany, "tblDealerCompany")

If bmb.Count = 0 Then

bmb.AddNew()

End If
 
Back
Top