locked
master-detail Update problem RRS feed

  • Question

  •  

    Easy & Urgent
    i am try to update simple master-detail form ... idid try this Code :

            Me.Validate()
            Me.PI_OrderHeaderBindingSource.EndEdit()
            Me.PI_OrderHeaderTableAdapter.Update(Me.DataSet1.PI_OrderHeader)

    ' whitch is generated by Designer

    but it dose not update my 2 tables

    i did try this code :

            Me.Validate()
            Me.PI_OrderHeaderBindingSource.EndEdit()
            Me.PI_OrderDetBindingSource.EndEdit()

            Me.PI_OrderDetDataGridView.EndEdit()

            If DataSet1.HasChanges Then
                DataSet1.PI_OrderDet.AcceptChanges()
                DataSet1.PI_OrderHeader.AcceptChanges()
                DataSet1.AcceptChanges()
                'Me.PI_OrderHeaderTableAdapter.Update(Me.DataSet1.PI_OrderHeader)

                PI_OrderHeaderTableAdapter.Update(DataSet1.PI_OrderHeader)
                PI_OrderDetTableAdapter.Update(DataSet1.PI_OrderDet)
            End If

    with this code there is no error ... and there is nothing in my 2 table

    i did check there is new data in the dataSet ... but why this wont updated 2 the database

    may be this help :

    Master Table

    OrderNo     Int  Identity column [PK]
    OrderDate  Date
    ...

    Detail Table

    OrderNo    Int
    ItemNo      Int

    Sunday, April 23, 2006 6:06 AM

Answers

  •  

    thanx

    i found out what i am missing here

    i have to AcceptChanges after the update the DataSet ... Not before

    Monday, April 24, 2006 4:16 AM

All replies

  • Hi there,

    When doing master-detail updates you have to do it in the right order. So, first do inserts (fitler DataSet.Changes by new rows) in master and then in detail, then do deletes in reverse order and finally do modifications.

    Sunday, April 23, 2006 11:12 AM
  •  

     i did insert just one 'Order' with just one Item ( in 'OrderDet' )

    i dont think there is less then that .

     

    and in my last code i did take care of the update order .

     

    ok lets Start from the beginning ... How do i implement the master-detail

    Sunday, April 23, 2006 11:33 AM
  •  

    thanx

    i found out what i am missing here

    i have to AcceptChanges after the update the DataSet ... Not before

    Monday, April 24, 2006 4:16 AM