updating DB & databinding of a textbox

HI,

I have VB studio.NETv2003,sqldatabase and a windows appl.

IN this I made a master/detail form, wich shows the mastertable and several
childtables.
I used the databinding of the form, to navigatethrough the dataset, and for synchronising
all the child tables with the mastertables. THIS IS GOING OK!

The only thing is, that the updating of the table is not working! what am I doing wrong
I would like the content of a textbox to update the data to the corresponding data
in the table, I doesn't do a thing!


INFO:
I initilise the dataadapters during formload.
The dataset is updated/deleted/inserted through this kind of code:
(each table has its own code, this is a example)
**********************************************************************
'update the ADDED and modified rows in the TBLGBPersoon table.
        dataTableChanges = nwDatasetInstance.tblGBpersoon.GetChanges(DataRowState.Added Or DataRowState.Modified)
        If (Not (dataTableChanges) Is Nothing) Then
            Try
                mdaDataAdapterGBPersoon.Update(dataTableChanges)
            Catch eUpdate As System.Exception
                If Err.Number = 5 Then
                    MsgBox("Verkeerde waarde in  'GB'.", MsgBoxStyle.Critical, "WARNING")
                Else
                    Throw eUpdate
                End If
            End Try
        End If
**********************************************************************



Can anyone help me


Answer this question

updating DB & databinding of a textbox

  • xuemingqiang

    me.bindingcontext(dataset,"ParentTable.RelationName").endcurrentEdit()

    You see you can have many levels and levels of tables Lets look at this

    Customer/Orders/OrderDetails

    three levels

    Lets say you make relations between customer and orders and orders and orderdetails.

    so your statement for the above (and how you naviagate and do data binding) would be.

    me.bindingcontext(dataset,"Customer.CustomerToOrdersRelation.OrdersToOrderDetailsRelation").encurrentEdit()

    To get to the last child table in a three level chain.

    It just chains up, this is also how you would bind a textbox to a child column of a child table.


    textbox1.databinding.add(new binding("Text",dataset,"Customer.CustomerToOrdersRelation.ChildColumnName"))

    THis example only is to bind to a child column in the orders table though, you have to do like I did above to bind it to a column in ordersdetail.

    Hope it helps.

  • hobeau

    I suspect you didn't call endcurrentedit before trying to update.

    me.bindingcontext(dataset,"tablename").endcurrentedit

    then call update of the adapter.

  • neverdone

    jfuentes, that was thw firt thing I tried,
    but it did not make the dataset to see any changes.....

    THIS IS THE SOLUTION:
    The tric was to get the right row via the parenttable to the childtable: 
    (datarowpersoon.GetChildRows("NameOfRelation"), 
    then via a small loop and set the rows to "ENDEDIT" 


    Maybe this is more complex then needed, but the following code works: 

    Code:
    'get the current row in table tblpersoon (MASTER TABLE) 
            Dim rowcounter As Integer = Me.BindingContext (nwDatasetInstance, "tblpersoon").Position 
      
           'get id from (MASTER TABLE) 
            Dim id As Integer = CType(nwDatasetInstance.Tables("tblpersoon").Rows(rowcounter).Item(0), Integer) 

            'get datarow for this id 
            Dim datarowpersoon As DataRow = nwDatasetInstance.Tables("tblpersoon").Rows.Find(id) 

           'get the row from the childtable, 
           'set the appropiate rows to endedit to make the dataset see anychanges 
            Dim datarowgbpersoon() As DataRow = datarowpersoon.GetChildRows("tblpersoontblGBpersoon") 

            Dim thisRow As DataRow 
            For Each thisRow In datarowgbpersoon 
                'debug.writeline(thisRow.Item("aanhef")) 
                thisRow.EndEdit() 
            Next 





    Still, if anybody knows a faster way of retreiving the datarow from childtable, please let me know 



    regards. 
    Reinier 

  • updating DB & databinding of a textbox