I get the following error :
Operator '??' cannot be applied to operands of type 'System.DateTime'
foreach (EndServReward r in reward)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
myIfxCmd.Parameters[0].Value = r.EmpNum ;
myIfxCmd.Parameters[1].Value = (r.ServDate) ?? DBNull.Value;
}
where reward is List<EndServReward> reward
,why this happens ,and how to fix it ?
??
is the null-coalescing operator.
It doesn't make sense to apply it to a value that cannot be null
.
The nullcoalescing operator cannot be applied by default on a type that is inherently non-nullable like DateTime
. If you wish to use it anyway, you'll have to foresee using DateTime
as a nullable type, using e.g. DateTime? dt;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With