I have a LINQ query in C# which runs on a datatable that is generated from a SQL Server exectution:
DataTable dtSubjects = db.ExecuteDataTable();
var subjectsWithoutParent = from row in dtSubjects.AsEnumerable()
where row["ParentID"] != DBNull.Value && row.Field<int>("ParentID") == 0
select row;
Afterwards, there’s a foreach that should run on each DataRow returned from the the LINQ. However, the foeach code does not run.
foreach (DataRow rowSubject in subjectsWithoutParent)
{
rowSubject["ParentID"] = DBNull.Value;
}
The Datatable has rows on it, and as far as I can tell subjectsWithoutParent gets at least one row from the LINQ.
Any ideas?
Try
and then check
subjectsWithoutParent.Any()is it retrieving data or not?