views:

252

answers:

1

I am loading my ADO.net dataset in by select query in command object. If I clear the dataset data with Acceptchanges will it delete the data in the sql server.

If not Please let me Know how to do?

+1  A: 

No, it will not.

You will have to make sure that each DataRow in your DataTable is marked as 'Deleted'. That is, the rowstate of each row will have to be set to Deleted. You can do that by traversing all rows, and call the Delete method for each Row.

Then, you'll have to call the Update method of the DataAdapter, before you call AcceptChanges. You have to call 'AcceptChanges' after you've done the changes in the DB, to indicate that the dataset / datatable does not contain anymore changes that have to be persisted in the DB. (Calling AcceptChanges will remove the DataRows that have a RowState of 'Deleted', and will change the RowState of all other DataRows to 'UnChanged'.

Frederik Gheysels