Well, you can just put multiple "where" clauses in directly, but I don't think you want to. Multiple "where" clauses ends up with a more restrictive filter - I think you want a less restrictive one. I think you really want:
DataTable tempData = (DataTable)grdUsageRecords.DataSource;
var query = from r in tempData.AsEnumerable()
where r.Field<string>("UserName") != "XXXX" &&
r.Field<string>("UserName") != "YYYY"
select r;
DataTable newDT = query.CopyToDataTable();
Note the && instead of ||. You want to select the row if the username isn't XXXX and the username isn't YYYY.
EDIT: If you have a whole collection, it's even easier. Suppose the collection is called ignoredUserNames
:
DataTable tempData = (DataTable)grdUsageRecords.DataSource;
var query = from r in tempData.AsEnumerable()
where !ignoredUserNames.Contains(r.Field<string>("UserName"))
select r;
DataTable newDT = query.CopyToDataTable();
Ideally you'd want to make this a HashSet<string>
to avoid the Contains
call taking a long time, but if the collection is small enough it won't make much odds.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…