Results 1 to 6 of 6

Thread: Data binding update problem

  1. #1

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96

    Data binding update problem

    I am having a problem getting a single field to update a dataset. In my "SaveInvoice" sub, I have several labels with a tag property that is bound to a field in the dataset. Before updating the underlying tables, I am assigning the proper values to the .tag properties of the various labels, and then doing an "EndCurrentEdit." However, when I update the database, I find that one of the properties did not update properly. If I step through the code line by line and check out the values, I see that all the tag properties have the proper value until executing the line with the EndCurrentEdit, at which point, the lblInvoiceStatus.tag reverts back to what it was before, for no apparent reason. None of the other tags seem to be doing this. I am using the ComponentOne data navigator thingie (C1InvoiceNavigator) and am calling the EndCurrentEdit method through it. Here is the code:

    Code:
        Private Sub SaveInvoice()
            Try
                'Save the current invoice to dataset and update the database
                
                Me.lblCustName.Tag = mintCurrentCustomer
                Me.lblInvVehicle.Tag = mintCurrentVehicle
                Me.lblInvoiceStatus.Tag = mintCurrentStatus
    
                'Convert tax and total values to decimal values and store in the .tag properties
                Me.lblSalesTax.Tag = IIf(Me.lblSalesTax.Text <> "", CType(Me.lblSalesTax.Text, Decimal), 0D)
                Me.lblTotal.Tag = IIf(Me.lblTotal.Text <> "", CType(Me.lblTotal.Text, Decimal), 0D)
                Me.lblBalanceDue.Tag = IIf(Me.lblBalanceDue.Text <> "", CType(Me.lblBalanceDue.Text, Decimal), 0D)
    
                'End the current edit
                Me.C1InvoiceNavigator.BindingContext(Me.dsInvoices1, "tblInvoices").EndCurrentEdit()
    
                'Update the underlying tables
                Me.daInvoices.Update(Me.dsInvoices1.tblInvoices)
                Me.daInvoiceDetails.Update(Me.dsInvoices1.tblInvoiceDetails)
                mblnNewInvoiceMode = False
                mblnInvoiceIsDirty = False
            Catch ex As Exception
                MsgBox(ex.StackTrace & vbCrLf & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical, "Error")
            End Try
    
        End Sub
    Any ideas why the EndCurrentEdit is causing lblInvoiceStatus.tag to revert back to its previous value?

    Thanks,
    Ken

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I haven't used this aproach to data editing but it looks as if your approach differs slightly from that recommended in MSDN help. Have a look at

    BindingManagerBase.EndCurrentEdit Method

    and compare it with your approach.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    I checked it out, and the first paragraph says this:

    Remarks
    This method is supported only if the data source implements the IEditableObject interface. In that case, changes will be saved. If the object does not implement the IEditableObject interface, changes made to the data will not be saved.
    So now I'm more confused than ever. Apparently, the only thing that implements the IEditableObject interface is a DataRowView. I'm guessing that when binding form objects to a data source, that you are actually binding to a DataRowView, right?

    I checked out their code samples, but the thing is, I thought with databinding, all that stuff was taken care of automatically. Their code is explictly creating a new datarow and modifying the values and replacing the old one, etc. Why do we have to do all of that?

    I think the solution will be to write the modified values directly to the DataRow in the Dataset and say the heck with the stupid tag properties. If I'm right, then what good is databinding? I've kinda noticed that experienced programmers tend to hate databinding and prefer to do all the data manipulation manually. I guess this is why.

    Thanks.

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    HI,

    I use databinding when using a datagrid as I have had problems with using datasource property. Presumably you are using a dataadapter and a dataset?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    Yeah. In the code I posted, daInvoices and daInvoiceDetails are the data adapters, dsInvoices1 is the dataset, and it contains two tables: tblInvoices and tblInvoiceDetails.

  6. #6

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    It's been over a week and I still can't squash this bug. The dataset is being updated properly. Everything in the dataset is as it should be. When I call the SaveInvoice sub, MOST of my data is saved to the database, with the exception of the lblInvoiceStatus.tag and also the lblClosedBy.Text. I have no idea why these particular two data bindings do not "stick" when all the other ones do.

    I've even tried directly updating the values in the datatable in the dataset. I know that the values in the dataset are 100% correct, and the rowstate value for the modified rows is 16 (which means modified). I assume since the rowstate is modified, the data adapter would know to update the underlying database, and it is updating most of the values, but only the two values described above are not getting updated in the database.

    Does anyone have any further suggestions for debugging this one? I've run out of ideas!

    Thanks,
    Ken

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