• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

Cannot Cause change on bound field

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.

Your thoughts?

On form:
    TextBox called 'txtTestID'
    TextBox called 'txtEmployeeName'
    TextBox called 'txtReportedTestDate'
    Button called 'btnSave'

in Code-Behind:
    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
    End Sub

    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")
    End Sub

    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")
            end if
            msgbox("No Updates found to be sent to DB")
       end if
    End Sub

1 Solution
I'm not sure about this, because I haven't yet worked with VB.NET 2005 enough to have sorted out all its quirks and how they differ from those of VB.NET 2003.  But my suggestion in a VB.NET 2003 context would be that, rather than using CONVERT to adapt the data when you bring it over from the database, you bring it over "as is" and use code in the FORMAT and PARSE events of the binding to get your display as you want it.  So far as I can see from the help file - see


- it should work in VB.NET 2005, too.  My thinking is that the Binding, or the DataAdapter, is refusing to do its job because it appears to it that there is a wrong data type being offered to it.  With FORMAT and PARSE, you can ensure that the datatype at datatable level is the same as at database level even if, for display purposes, it is different.

pumbaacaAuthor Commented:
Sancler - you have me going in the right direction.  What you stated makes sense but I could not yet figure out how to incorporate it (I don't understand fully the iformat constructs).  Also, I am using the new .NET framework 2.0 bindingsource object which didn't seem to have the same property and methods described in the link you provide.

It got me thinking, however, to put the data in its original format (smalldatetime) from the database and use the datetimepicker object on my form.  It performs what I needed and seems to be acceptable to the bindingsource object...it allows an update to the databse.  It saved me a little time in not having to delve into understanding the iformat constructs just yet!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now