Find and delete a specific row from datatable
If you want to delete specific, multiple or single row delete from data table using by specific condition. Try to below code.
You can delete multiple or single row from data table. There is many ways to delete rows from data table. Try Below code.
Try to below code. You can delete multiple or single row from data table. There is many ways to delete row(s) from data table.
1.Delete multiple rows.
string _filterName_needed="approved";
DataRow[] drr = dt.Select("status=' "+ _filterName_needed +" ' ");
for (int i = 0; i < drr.Length; i++)
{
dt.Rows.Remove(drr[i]);
}
.....................................................Delete only row.
string _filterName_needed="approved";
object obj = dt.Select("status=' "+_filterName_needed+" ' ");
DataRow drr = dt.Rows.Find(obj);
if (drr!=null)
{
drr.Delete();
}
**but you must know that your table must have a primery key to use this method.Delete row with for loop
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (dt.Rows[i]["status"].ToString() == "approved")
{
dt.Rows[i].Delete();
}
}
I hope it will be useful to developer..
so useful for beginners.thanks for post