Cannot Cause change on bound field

Posted on 2006-05-06
Last Modified: 2012-08-13
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

Question by:pumbaaca
    LVL 34

    Accepted 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.


    Author Comment

    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 allows an update to the databse.  It saved me a little time in not having to delve into understanding the iformat constructs just yet!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now