I am trying to use compare dates in a query. I have d and p are rows selected from different datatables.I want to retrieve fields from datatables based on condition. I have below conditions but throwing an error when any one of the below date is Null or empty.
I tried below statements-
join d in Data.AsEnumerable()
on p.Field<String>("EMPLID") equals
d.Field<String>("EMPLID")
where (Convert.ToString(d.Field<DateTime>("CONTRACT_START"))!=null) && (Convert.ToString(d.Field<DateTime>("SIGNED_DT"))!=null) && (Convert.ToString(d.Field<String>("ACT_DT"))!=null)
Throwing an error- Can not cast DBNull.Value to Sysytem .date Time . Please use a nullable types.
when above condition is true( values are not null then I want to exceute below statement in a query)
where (d.Field<DateTime>("CONTRACT_START") >= sd && d.Field<DateTime>("CONTRACT_START") <= ed) ||Convert.ToString(d.Field<DateTime>("SIGNED_DT"))!=" " && d.Field<DateTime>("SIGNED_DT") > d.Field<DateTime>("CONTRACT_START") || d.Field<DateTime>("ACT_DT") > d.Field<DateTime>("CONTRACT_START"))
How to check if the values are not null then execute the condition using in a query in C#.