I'm kinda new to programming with BindingSources and DataNavigators (as well as VB .NET) so here's my question/problem.
I'm programming an app in VB 2010 in which users will update data in a SQL 2008 R2 server on the back end. The form in design mode has a BindingSource, DataSet and the various textboxes for the data and check boxes and a DataNavigator at the bottom of the form.
When the form loads a DataAdapter is loaded and then the dataset is loaded. (code for the connection omitted, "text_table" is a test table in the SQL server.
frmDataAdapter = New SqlClient.SqlDataAdapter(SQL_Query, frmConnection)
frmConnection.Open()
frmDataAdapter.FillSchema(frmDataSet, SchemaType.Source, "test_table")
frmDataAdapter.Fill(frmDataSet, "test_table")
I bind the BindingSource to the DataSet and to the DataNavigator...
With frmBindingSource
.DataMember = "test_table"
.DataSource = frmDataSet
End With
frmBindingNavigator.BindingSource = frmBindingSource
And I bind the textboxes and checkboxes to the BindingSource...
With Me
.Date_Logged.DataBindings.Add("Text",frmBindingSource, "DateLogged", True, DataSourceUpdateMode.OnValidation, vbNullString, "MM/dd/yyyy")
.Prepared_By.DataBindings.Add("Text", frmBindingSource, "PreparedBy", False, DataSourceUpdateMode.OnValidation, vbNullString)
.Issue_Placement.DataBindings.Add("Text", frmBindingSource, "IssuePlacement", False, DataSourceUpdateMode.OnValidation, vbNullString)
.Completed.DataBindings.Add("Checked", frmBindingSource, "Completed", False, DataSourceUpdateMode.OnValidation, False)
End With
The problem is, that while the "Completed" checkbox is bound to the "frmBindingSource", if I press the add record button on the BindingNavigator all the other controls (textboxes) don't clear out so the user can enter new data, but does create a new record as the count in the DataNavigator increments. (At that point I usually stop the program from actually saving anything to the table.)
If I remove the binding for the "Completed" checkbox then try it again, when I press the add record button the other textboxes clear out as they should. Put the "Completed" checkbox binding back in and it stops working.
The "Completed" field in the SQL server is "bit" with a default of "0" so all the data has valid entries, nothing is NULL in the "Completed" Field. I've tried binding the "Completed" checkbox all sorts of ways and always have the same issue.
Currently there's no validation code or any other real events as this is at the start of the project but it's kinda annoying as I need to use checkboxes.
Anyone have any ideas what I'm doing wrong here?