Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Delete Rows in a DataTable 

In order to retain the information that the dataset needs to send updates to the data source, use the Delete method to remove rows in a data table. For example, if your application uses a TableAdapter (or DataAdapter), the adapter's Update method will delete rows in the database that have a RowState of Deleted.

If your application does not need to send updates back to a data source, then it is possible to remove records by directly accessing the data row collection (Remove). For information on locating a specific row in a DataTable, see How to: Locate a Specific Row in a DataTable.

To delete records from a data table

  • Call the Delete method of a DataRow.

    This method does not physically remove the record; instead, it marks the record for deletion.


    If you get the count property of a DataRowCollection, the resulting count includes records that have been marked for deletion. To get an accurate count of only records that are not marked for deletion, you can loop through the collection looking at the RowState property of each record (records marked for deletion have a RowState of Deleted). Alternatively, you can create a data view of a dataset that filters based on row state and get the count property from there.

    The following example shows how to call the Delete method to mark the first row in the Customers table as deleted:


  • For untyped datasets, use code similar to the following:


See Also

Community Additions

© 2015 Microsoft