Home All Groups Group Topic Archive Search About

Deleting a Row from Datatable and from Database

Author
29 Apr 2006 11:23 PM
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

Author
30 Apr 2006 12:40 AM
Chris Chilvers
>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.

AddThis Social Bookmark Button