none
Tableadapter delete wont update to database RRS feed

  • Question

  • Hi, please can anyone help, when I insert a new row and update using the tableadapter, it works fine, but when I remove a row and update, the row is not removed from the database. I have tried all sorts of stuff, read the info on tableadapters but still can't get the delete to work. Any help would be most appreciated. Here is the code :

     Private Sub btnDelete(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click  
            If BookingsDataGridView.CurrentRow.Cells("UserID").Value = Login.LoggedIn And BookingsDataGridView.CurrentRow.Cells("BookDate").Value > Now Then 
                Dim s As Integer = BookingsDataGridView.CurrentRow.Cells("BookingID").Value  
                RoomsDataSet.Bookings.RemoveBookingsRow(RoomsDataSet.Bookings.FindByBookingID(s))  
                BookingsTableAdapter.Update(RoomsDataSet)  
                        ElseIf BookingsDataGridView.CurrentRow.Cells("UserID").Value <> Login.LoggedIn Then 
                MsgBox("You cannot delete bookings made by another user")  
            ElseIf BookingsDataGridView.CurrentRow.Cells("BookDate").Value < Now Then 
                MsgBox("You cannot delete bookings made prior to the current date")  
            End If 
     
            TableAdapterManager.UpdateAll(RoomsDataSet)  
     
        End Sub 
    Saturday, January 31, 2009 5:57 AM

All replies

  •   Problem solved by franking in another thread, here it is :
     
    franking - Posted 6 hours 12 minutes ago
    The RemoveBookingsRow() method is designer generated code. You can't use it to delete rows from a table. It uses DataRowCollection.Remove() to remove the row from the collection. Afterwards the row state of the removed row will be DataRowState.Detached and not DataRowState.Deleted. This is by design.

    To delete a row, select the row to be deleted and call the Delete() method:

    // ... some code above 
     
    BookingsRow row = RoomsDataSet.Bookings.FindByBookingID(s); 
    if (row != null) row.Delete(); 
     
    // ... rest of the code 

    hope this helps,
    franking
    Sunday, February 1, 2009 7:50 AM