I need to add an additional filter to this LINQ statement but I can’t seem to get it correct
var _duplicateRows =
dt.AsEnumerable().GroupBy(
myRow =>
new
{
accidentYear = myRow.ItemArray[1].ToString().Trim(),
reviewLine = myRow.ItemArray[2].ToString().Trim()
}).Where(grp => grp.Count() > 1).Select(grp => grp.Key);
What I need is to exclude and rows where accidentYear and reviewLine are Null Or Empty
TIA
–EDIT
Hey guys, I just wanted to update the post. I decided to go with this to clean the datatable before I even got to the grouping.
public DataTable GetCleanDataTable(DataTable dt)
{
IEnumerable<DataRow> _query =
dt.AsEnumerable().Where(
dt1 =>
(!Convert.IsDBNull(dt1.ItemArray[0].ToString()) &&
!Convert.IsDBNull(dt1.ItemArray[1].ToString()) &&
!Convert.IsDBNull(dt1.ItemArray[2].ToString())));
return _query.CopyToDataTable<DataRow>();
}
Add a where clause to your datatable.
A cleaner approach: