Deleting a Row from Datatable and from Database

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
 
C

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top