var query = (from dt1 in dta.AsEnumerable()
join dt2 in dtb.AsEnumerable()
on dt1.Field<string>("column1") equals dt2.Field<string>("column1")
into outer
from Dt2 in outer.DefaultIfEmpty()
group new { Dt2 } by new { SearchKey = dt1.Field<string>("SearchKey") } into g
select new
{
Status = g.Select(r => r.Dt2) == null ? string.Empty : g.Select(r => r.Dt2.Field<string>("Column2")).ToList()[0]
});
foreach (var row in query)
{
dt.Rows.Add(row.Status.ToList()[0]);
}
So a rundown of the linq statement: I have 2 datatables which I am using a left join with. I am trying to query the second datatable with a group by. I check for null, and if it is null, I give it a string.Empty otherwise it should contain the value of the column. I then use a foreach statement to loop through the rows, but it will hit a null value and give me the error "Value cannot be null. Parameter name: row". It's like it doesn't even check for nulls. Does anyone happen to know how to fix this? I have this in a try catch to catch the error if anyone tries to reproduce it. Any help would be much appreciated. Thanks!