We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Deleting a master record in a master-detail relationship

I''m having a problem deleting the master record in a master-detail relationship. Pressing the delete key removes the record from the grid, which is expected. However, the master record is not deleted from the SQL table. The child records are removed, but the master record remains. Looping through the master datatable causes an exception when it hits the "deleted" record: System.DAta.DeletedRowInaccessibleException: Deleted row information cannot be accessed through the row........ I do notice that the rowstate is marked "Deleted", but there is no ItemArray information available. Any ideas? Thank you!

6 Replies

AD Administrator Syncfusion Team May 24, 2005 01:19 PM

Have you tried calling Datatable.AcceptChanges on your master table?


HS Helmut Scheiss May 24, 2005 02:18 PM

I''ve included the following save function code. As you can note, I handle the order of the detail record updates separately: Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim ds1 As DataTable Dim ds2 As DataTable Dim ds3 As DataTable ds1 = DsQA1.dbo_frmNewQASELECTQADetailDetails.GetChanges(DataRowState.Deleted) ds2 = DsQA1.dbo_frmNewQASELECTQADetailDetails.GetChanges(DataRowState.Added) ds3 = DsQA1.dbo_frmNewQASELECTQADetailDetails.GetChanges(DataRowState.Modified) Try ''Delete child records If ds1 Is Nothing Then Else daDetailDetail.Update(ds1) ds1.Dispose() End If ''Apply master changes daDetail.Update(DsQA1, "dbo_frmNewQASELECTQADetails") ''Apply child adds If ds2 Is Nothing Then Else daDetailDetail.Update(ds2) ds2.Dispose() End If ''Apply child updates If ds3 Is Nothing Then Else daDetailDetail.Update(ds3) ds3.Dispose() End If ''Accept all changes in the Dataset DsQA1.AcceptChanges() ''Clear tables in dataset DsQA1.Tables("dbo_frmNewQASELECTQADetailDetails").Clear() DsQA1.Tables("dbo_frmNewQASELECTQADetails").Clear() ''Reload tables from database daDetail.Fill(DsQA1.dbo_frmNewQASELECTQADetails) daDetailDetail.Fill(DsQA1.dbo_frmNewQASELECTQADetailDetails) ''Refresh the grids DataGrid1.Refresh() DataGrid2.Refresh() Return This is the stored procedure linked to the SQLDelete command for the master grid: ALTER PROCEDURE dbo.frmNewQADELETEQADetails (@QADetailID int) AS DELETE FROM tblNewQADetail WHERE QADetailID = @QADetailID >Have you tried calling Datatable.AcceptChanges on your master table?


AD Administrator Syncfusion Team May 24, 2005 05:10 PM

Before calling update on the master datatable, does this ds1 = DsQA1.Tables("dbo_frmNewQASELECTQADetails").GetChanges(DataRowState.Deleted) return what you expect? If so, you might try calling update on this ds1 to see if that will push the deletes back to your database.


HS Helmut Scheiss May 25, 2005 04:43 AM

I made a similar statement : ds4 = DsQA1.Tables("dbo_frmNewQASELECTQADetails").GetChanges(DataRowState.Deleted) I then deleted 2 rows from the master grid. When I try to save, ds4 has 2 rows in its Count property. However, I get a "cannot view indexed property" when trying to view the Item property. One of the rows had children, which were deleted, but both master rows remained. Even after closing the application, checking the database, they are still there. This is wierd! >Before calling update on the master datatable, does this > >ds1 = DsQA1.Tables("dbo_frmNewQASELECTQADetails").GetChanges(DataRowState.Deleted) > >return what you expect? If so, you might try calling update on this ds1 to see if that will push the deletes back to your database.


HS Helmut Scheiss May 25, 2005 05:03 AM

A little more info: I changed the ContinueUpdateOnError for the daDetail adapter to False and am getting a DBConcurrency violation: the DeleteCommand affected 0 rows. This occurs when it tries to apply the deletes to the the master table. I''m the only one using this, so where is the concurrency violation?


AD Administrator Syncfusion Team May 25, 2005 06:46 AM

Try changing the order of things. Go ahead and update dbo_frmNewQASELECTQADetails before you delete the child rows to see if this is what is causing this problem.

Loader.
Live Chat Icon For mobile
Up arrow icon