Deleting Records in a Dataset
In order to retain the information that the dataset needs to properly update the data source, use the Delete method to remove rows in a data table. If your application does not need to send updates back to a data source then it is possible to remove records by directly accesing the data row collection.
To delete records from a data table
- Call the data row's Delete method.
This method does not physically remove the record; instead, it marks the record for deletion.Note 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. 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:
' Visual Basic DsCustomers1.Customers.Rows(0).Delete() // C# dsCustomers1.Customers.Rows.Delete();