You can delete a record by calling Resultset.Delete() with either an index, or a record object:


rs.Delete(3);

rs.Delete(record);


If you want to remove all the resultset's records at once call Resultset.Clear():


rs.Clear();

Deleting multiple records in a loop

Read this part carefully when you plan to delete multiple records in a loop or a foreach enumeration.


Deleting a single Record in a for or foreach is not a problem.


Enumerating will not work:


EmployeesRecordset rs = new EmployeesRecordset();

rs.Append();

rs.Append();

rs.Append();

rs.Append();

rs.Append();


foreach (var record in rs)

   rs.Delete(record);


You expect the enumeration to end with a rs.RecordCount of 0, but instead you end up with 3 records left in the resultset. This is because rs.Delete() changes the length of the list you are enumerating with foreach, and that confuses the enumerator.


A regular for loop also doesn't work.


The solution is to use a reverse for loop. Only a reverse loop will delete multiple records correctly:


for (int x = rs.RecordCount - 1; x >= 0; x--)

{

   EmployeesRecord record = rs[x];


   if (record.Address.StartsWith("M"))

       rs.Delete(x); // or rs.Delete(record);

}