Eugene Zalivadnyi
Eugene Zalivadnyi

Reputation: 477

How to verify row existence and delete it from DataTable using Linq or Select command?

Maybe I must use sometning like this:

var rows = ds.Tables["points"].Select("pupil_id == tempPupilId, discipline_id == intSelectedDisciplineId, point == Convert.ToInt32(currValue), point_date == dayToInsert");
           foreach (var row in rows)
           {
           row.Delete();
           }

But how check that this row is exists in Database?

Upvotes: 1

Views: 122

Answers (1)

Rafał Czabaj
Rafał Czabaj

Reputation: 740

You can try this:

var rowsToDelete = (from row in ds.Tables["Points"].AsEnumerable()
                   where row.Field<type>("pupil_id") == tempPupilId //(i guess that you have it on code side, if not compare it in the same awy) 
                   && row.Field<type>("discipline_id") == intSelectedDisciplineId && etc..
                   select row).ToList();
foreach (var r in rowsToDelete)
  r.Delete();

Upvotes: 1

Related Questions