Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete a row in datatable not working

Status
Not open for further replies.

llmclaughlin

Programmer
Aug 20, 2004
140
US
Does anyone see anything wrong with this. It goes through the row.delete but doesn't delete the row.

If Not dbTABLE_RESHIP Is Nothing Then
With dbTABLE_RESHIP
If .Rows.Count > 0 Then
For iDEL = 0 To .Rows.Count - 1
For iFND = 0 To dbTABLE.Rows.Count - 1
If .Rows(iDEL).Item(4) = dbTABLE.Rows(iFND).Item(4) Then
dbTABLE.Rows(iFND).Delete()
dbTABLE.AcceptChanges()
Exit For
End If
Next
Next
End If
End With
End If


Thanks

Louie
 

The problem is this line:

dbTABLE.AcceptChanges()

When you call AcceptChanges it does just that...it accepts any changes to the datatable. When you delete a row in a datatable, it isn't actually "gone", its RowState is set to DataRowState.Deleted. When you call the Update method later to save changes in the datatable to the database, any rows with DataRowState.Deleted are removed from the appropriate table in the database. When you call AcceptChanges, any rows with DataRowState.Deleted are removed from the datatable (and inserts, updates, etc. are performed *on the datatable*), and any remaining rows in the datatable have their RowState set to DataRowState.Unchanged. So later when you call the Update method, nothing happens because all of the datatable's rows show DataRowState.Unchanged.

In short, just remove that line and your delete should work (assuming all the appropriate commands are set). You don't need to call AcceptChanges at all, as the Update method calls AcceptChanges after the Update is finished.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top