Results 1 to 4 of 4

Thread: Data Bound Control Problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    71

    Data Bound Control Problems

    I fixed one problem by binding controls to a dataset and created two more.

    I an setting up a binding context like this:
    Me.CustDataAdapter.Fill(DsCustomer1, "Customer")
    bmb = Me.BindingContext(DsCustomer1, "customer")

    Then I display the records full screen with one textbox for each field of data. I have command buttons for Next, Prev, Firsrt and Last which use the bindings like this:

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
    If bmb.Position > 0 Then
    bmb.Position -= 1
    End If
    End Sub

    Problem is, I cant update the dataset with new or changed records. After changes to the dataset I call the Update method of the CustDataAdapter, but nothing happens. If I test for dataset.HasChanges() it always comes back false.

    For example, if you press the New Record button I clear the databound fields by doing this:
    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
    bmb.AddNew()
    End Sub

    Then fill in the blanks and press Save which does this:

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

    CustDataAdapter.Update(DsCustomer1)
    End Sub

    There are no errors, but the new record is not saved. If I change a value on an existing record and do the Update, the change is not saved either. Calling the AcceptChanges method before the Update does no good either.

    So what am I doing wrong?

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Unhappy

    I don't have an answer for your problem. Sorry.

    But i did want to say that the problems you're having is the exact reason why i gave up trying to bind controls to a database. I always found it created more problems than it solved.

    I suggest you just do data validation, control population, and data saving in a series of small custom made functions. If you do it right, you'll actually have some very re-usable code for later in your application.
    ~Peter


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    I agree. I left the bindings in for navigation buttons and coded the rest. Much better.

  4. #4
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Smile

    Cool.
    ~Peter


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width