?
Solved

Cannot Cause change on bound field

Posted on 2006-05-06
2
Medium Priority
?
584 Views
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)
       MyBase.New()
       InitializeComponent()
       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
       bsTable.EndEdit()
       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
                ReqDS.Merge(dtChanges)
                ReqDS.AcceptChanges()
                Me.Close()
            Else
                msgbox("DB update returned an error")
            end if
       else
            msgbox("No Updates found to be sent to DB")
       end if
    End Sub


0
Comment
Question by:pumbaaca
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 1500 total points
ID: 16621892
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

 http://msdn2.microsoft.com/en-US/library/system.windows.forms.binding.format.aspx

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

Roger
0
 

Author Comment

by:pumbaaca
ID: 16622591
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!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

831 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