none
Deleting Particular Data Row in One to Many form RRS feed

  • Question

  • Hello

    I am using VB 2008 & MS Access Database with Typed Dataset And Bound Controls. I have designed a master/detail type form for Goods Receipt & Goods Receipt Details.

    My problem is i want to allow user to Delete Single Data Row in DataGridView from Details Section while editing.

    I am able to delete the said Row from DataGridView however unable to save it.

    The Update command gives following error - "Update Requires a valid DeleteCommand when passed DataRow collection with deleted rows".

    I checked with Dataset & found that no DeleteCommand Generated for the Details table in Table Adapter.

    i have used following code

        Private Sub btnDeleteRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteRow.Click
    
            If ConfirmDeleteRecord() Then
    grdGoodsReceiptDetails.Rows.RemoveAt(grdGoodsReceiptDetails.CurrentCell.RowIndex)         
    
               
            End If
        End Sub
    
        Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            Try
                If isValidData() Then
                    Me.Validate()
                    Me.bsGoodsReceipt.EndEdit()
                    Me.taGoodsReceipt.Update(Me.dsGoodsReceipt.GoodsReceipt)
    
                    Me.bsGoodsReceiptDetails.EndEdit()
                    Me.taGoodsReceiptDetails.Update(Me.dsGoodsReceipt.GoodsReceiptDetails)
    
                    EntryDate = dtReceiptDate.Value
                    bAddMode = False
                    bEditMode = False
    
                    statusRecordSaved()
                    btnEnableDisable(True)
                Else
                    MessageBox.Show("FIELDS CAN NOT BE LEFT BLANK")
                End If
    
            Catch ex As Exception
                MessageBox.Show(ex.Message, ex.GetType.ToString)
            End Try
        End Sub


    Monday, March 12, 2012 4:01 AM

Answers

  • Hello

    Based on the issue i have reserched the cause of problem & found that the reason why Delete Command is not generated for Table Adapter in DataSet is due to Primary Key Column in Details Table.

    Because the Primary Key column is not defined for the table in the database adding such table in Dataset doesn't add Delete Command for it vice versa if i do define a primary key column for one of column in table in the database & readd the table to dataset, the Delete command for it is now generated.

    reason why the Update method gives error saying it requires Valid Update Command.

    SANDEEP

    Thursday, March 29, 2012 3:57 AM

All replies

  • If you don't use version 2008 or later than it is a long way to explain, otherwise use the TableAdapterManager which is made for your problem.

    http://msdn.microsoft.com/en-us/library/bb384426.aspx


    Success
    Cor

    Monday, March 12, 2012 8:12 AM
  • Hi SANDEEP JAKHOTYA,

    Welcome to MSDN Forum.

    I agree with @Cor Ligthert, you can use TableAdapterManager to do hierarchical update. Addition to Cor Ligthert's link, here's a walkthrough about hierarchical updating, please refer to it.

    Walkthrough: Saving Data from Related Data Tables (Hierarchical Update)

    Another link will help with the existing project,

    How to: Implement Hierarchical Update in Existing Visual Studio Projects

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, March 13, 2012 7:14 AM
    Moderator
  • I have used both ways already

    1st with TableAdapterManager - Me.taManager.UpdateAll(Me.dsGoodsReceipt)

    which gave me Same Error. To find out which table adapter is actually having a problem i splited the Update Command as in my code & found the Second (Table for Details record) table adapter is having problem.

    I did deleted the Related table from DataSet and re Added using wizard, even then found that no Delete Command is added Table Adapter.

    SANDEEP

    Saturday, March 17, 2012 1:38 PM
  • Hi SANDEEP JAKHOTYA,

    Based on the issue, could you please upload the project to SkyDrive and post the link here? I will test it and help you to find the root cause.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 19, 2012 8:28 AM
    Moderator
  • Hello

    Based on the issue i have reserched the cause of problem & found that the reason why Delete Command is not generated for Table Adapter in DataSet is due to Primary Key Column in Details Table.

    Because the Primary Key column is not defined for the table in the database adding such table in Dataset doesn't add Delete Command for it vice versa if i do define a primary key column for one of column in table in the database & readd the table to dataset, the Delete command for it is now generated.

    reason why the Update method gives error saying it requires Valid Update Command.

    SANDEEP

    Thursday, March 29, 2012 3:57 AM