Cannot Cause change on bound field
Posted on 2006-05-06
I have a number of textboxes on my form that are all bound to a bindingsource object. About half of the textboxes correctly cause a datarow to be "updated" and update the data in the database. The other half just won't. I cannot see what difference the fields are between themselves. Both are defined essentially the same (as varchar fields). The main difference is that the ones that don't work are date fields.
From the database, I get the date fields formatted as mm/dd/yyyy (using the Convert 101 formatting). They correctly display in the textbox. I try to change the year within the textbox...which causes a change event no problem. When I do a bindingsource endedit, it does not appear to save the change to the underlying datarow that the textbox is bound to. As a result, there is no changed datarow to be updated by the data adapter.
Below is a condensed version of my source. I am calling this form from another form, passing the Data adapter, dataset, and a variable (to look up the datarow in the dataset). The update of the employeename field works fine. The reportedTestDate does not. If I change both fields together, only the employeeName field successfully updates, reportedTestDate does not.
TextBox called 'txtTestID'
TextBox called 'txtEmployeeName'
TextBox called 'txtReportedTestDate'
Button called 'btnSave'
Private ReqTestID As Integer
Private ReqDA As SqlClient.SqlDataAdapter
Private ReqDS As DataSet
Private bsTable As BindingSource
Public Sub New(ByRef DATests As SqlClient.SqlDataAdapter, _
ByRef DSTests As DataSet, ByVal RTestID As Integer)
ReqDA = DATests
ReqDS = DSTests
ReqTestID = RTestID
Private Sub frmTestDetails_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
bsTable = New BindingSource
bsTable.DataSource = ReqDS.Tables(0)
bsTable.Position = bsTable.Find("TestID", ReqTestID)
txtTestID.DataBindings.Add("text", bsTable, "TestID")
txtEmployeeName.DataBindings.Add("text", bsTable, "EmployeeName")
txtReportedTestDate.DataBindings.Add("text", bsTable, "ReportedTestDate")
Private Sub btnSave_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnSave.Click
Dim dtChanges As DataTable
dtChanges = ReqDS.Tables(0).GetChanges()
if dtChanges.rows.count > 0 then
dim intReturn as integer = ReqDA.Update(dtChanges)
If intReturn > 0 Then
msgbox("DB update returned an error")
msgbox("No Updates found to be sent to DB")