[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

master-detail Update problem


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
0
hatem72
Asked:
hatem72
  • 2
  • 2
1 Solution
 
hatem72Author Commented:


i found out what i am missing here

i have to AcceptChanges after the update the DataSet ... Not before
0
 
RobertRFreemanCommented:
Note:  You should not use AcceptChanges at all.
The adapter will automatically call AcceptChanges as part of the update.
0
 
hatem72Author Commented:


hi RobertRFreeman

thanx for ur advice ... but i did read this [ Using AcceptChanges ] somewhere with the update
    [ still learning ]
i was close to go back to vb6 becuase of this problem ... i stuck there for weeks

any way thank god again ... and for ur advice u well have the points
0
 
RobertRFreemanCommented:
:)

Note on AcceptChanges:
The datatable keeps track of the RowState for each row in the table.  EX: Inserted, Modified, Deleted, Unchanged.
The Adapter.Update uses the rowstate to know whether the row has changed and if so, what Command to execute.
(Inserted = InsertCommand, Modified = UpdateCommand, Deleted = DeleteCommand).
After updating each row, the Adapter.Update sets the RowState back to Unchanged (via AcceptChanges).

The DataRow also keeps a copy of the last Unchanged version of itself, so if you want to Undo changes, you can call RejectChanges on the row.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now