I have a DataTable and I want to remove all the rows matching a List< string>
, how to do that? Following is my code,
public static DataTable GetSkills(List<Skill> EnteredSkills)
{
DataTable dt = new DataTable();
dt = GetDBMaster("SkillMaster");
List<string> MatchingSkills = EnteredSkills.Select(c => c.Text).ToList();
//Logic to Delete rows MatchingSkills from dt here
return dt;
}
Final Solution
public static DataTable GetSkills(List<Skill> EnteredSkills)
{
DataTable dt = new DataTable();
dt = GetDBMaster("SkillMaster");
var MatchingSkills = new HashSet<string>(EnteredSkills.Select(c => c.Text));
List<DataRow> removeRows = dt.AsEnumerable().Where(r => MatchingSkills.Contains(r.Field<string>("DataTableSkillColumnName"))).ToList();
removeRows.ForEach(dt.Rows.Remove);
return dt;
}