I'm trying to filter a DataTable using LINQ
DataTable DT=new DataTable();
DT = PinDicDAO.GetContractPOVD().AsEnumerable().Where(r => (r.Field<string>("ContractPOReference").ToUpper().Contains(text.ToUpper())) || (r.Field<string>("ContractPO").ToUpper().Contains(text.ToUpper())) ||
(r.Field<string>("ContractPOTitle").ToUpper().Contains(text.ToUpper())) || (r.Field<string>("Address").ToUpper().Contains(text.ToUpper()))
).AsDataView().ToTable();
Query works fine. But when some fields have NULL values it gives a Exception.
"Object Reference Not set to an instance of object"
How can I avoid this exception?
r.Field<string>("ContractPOReference != null ...