I have been attempting to write a reusable generic method for lookups on a DataTable. What I have so far:
private static IEnumerable<DataRow> GetRow<FType>(string Tablename,
string Fieldname, FType Match)
{
var result = from row in dataSet.Tables[Tablename].AsEnumerable()
where row.Field<FType>(Fieldname) == Match
select row;
return result;
}
However, we don’t like the row.Field<FType>(Fieldname) == Match.
Any ideas on what I’m suppose to do to fix this? I get: Operator ‘==’ cannot be applied to FType and FType.
Replace
== Matchwith.Equals(Match)and you should be good. I’ve thrown in a null check in case the values could be null.