updateproblem in master/detail tables

reinier

Member
Joined
Jan 11, 2005
Messages
6
Programming Experience
3-5
HI foks, (this is my first post)

(I am getting really tired of this problem:)

I have a form with a master/detail on it, wich shows the mastertable
and the childtables, the tables are related to eachother correctly.

The strange thing is, that navigating through the master/detail is going very well,
only updating a CHILDTABLE is going very bad.
The textbox in wich text is changed, doesn't 'tell' the dataset, that something has changed.....


1)The datablechanges has 1 row, that is, when there is a modification or a add in a table of the dataset.
2) the update/delete/insert commands are initialised during the load_form vent,
here is a small one:


Code:

Private Sub InitializeFunctieGezochtAdapter()
'
'SqlDataAdapter5
'
Dim SqlSelectCommand5 As New System.Data.SqlClient.SqlCommand
Dim SqlInsertCommand5 As New System.Data.SqlClient.SqlCommand
Dim SqlUpdateCommand5 As New System.Data.SqlClient.SqlCommand
Dim SqlDeleteCommand5 As New System.Data.SqlClient.SqlCommand

'
'SqlSelectCommand5
'
SqlSelectCommand5.CommandText = "SELECT id_persoon, id_functiegezocht, functiegezocht FROM tblFunctieGezocht"
SqlSelectCommand5.Connection = objconn
'
'SqlInsertCommand5
'
.......................................
'
'SqlUpdateCommand5
'
...................................... '
'SqlDeleteCommand5
'
........................................

mdaDataAdapterFunctieGezocht = New SqlDataAdapter
mdaDataAdapterFunctieGezocht.DeleteCommand = SqlDeleteCommand5
mdaDataAdapterFunctieGezocht.InsertCommand = SqlInsertCommand5
mdaDataAdapterFunctieGezocht.SelectCommand = SqlSelectCommand5
mdaDataAdapterFunctieGezocht.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "tblFunctieGezocht", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("id_persoon", "id_persoon"), New System.Data.Common.DataColumnMapping("id_functiegezocht", "id_functiegezocht"), New System.Data.Common.DataColumnMapping("functiegezocht", "functiegezocht")})})
mdaDataAdapterFunctieGezocht.UpdateCommand = SqlUpdateCommand5
End Sub



( I shortened it of course)

I use buttons to navigate through the master/detail, example: the next button has the following code:


Code: Me.BindingContext(nwDatasetInstance, "tblpersoon").Position = (Me.BindingContext(nwDatasetInstance, "tblpersoon").Position + 1)



*******************************************************************************************
I used the bindingcontext of a form to synchronize the master/detail tables in a dataset,
ain't there another way of synchronizing, without this terrible bindingcontext?


Anyway, great that you reacted,

Regards,
Reinier
sad.gif
sad.gif
sad.gif
sad.gif
sad.gif
sad.gif
sad.gif
sad.gif
sad.gif
sad.gif
 
Solved !!!!!!!!

This is the best solution sofar, I quote:

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

**********************************************************



OR 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
thumb-up.gif
 
Last edited:
Back
Top