Deleting a Row from Datatable and from Database

  • Thread starter Thread starter CMC
  • Start date Start date
C

CMC

Hi,

I've a Datagridview binded with a Datatable. With this code:

DataTable.rows.remove(current_datarow)
DataAdapter.update(datatable)

.... I manage to delete the row from the DataTable, it disapears from the
DataGridView, but it doesn't delete it from he database (after updating the
DataAdapter).

Can anyone tell me where is the problem ?!

Thanks
CC
 
DataTable.rows.remove(current_datarow)

From the docs, DataRowCollection.Remove:
"When a row is removed, all data in that row is lost. You can also call
the Delete method of the DataRow class to just mark a row for removal.
Calling Remove is the same as calling Delete and then calling
AcceptChanges."

Thus calling remove completly removes that row from the table leaving no
trace of it. The command you want to use is:

current_datarow.Delete()

This will mark the row for deletion, when you next run update it will
run the delete command then remove the row from the DataTable.
 
Back
Top