c# ado.net: nulls dbnull -- there some-more fit syntax?
i've got datetime? i'm perplexing insert domain controlling dbparameter. i'm formulating parameter so:
dbparameter dateprm = updatestmt.createparameter();
dateprm.parametername = "@change_date";
and following i wish put value datetime? dataprm.value while accounting nulls.
i guess primarily i'd clever:
dateprm.value = nullabledate ?? dbnull.value;
but fails error
operator '??' can't receptive operands form 'system.datetime?' 'system.dbnull'
so i speculation wholly works second justification non-nullable chronicle initial argument. following i went for:
dateprm.value = nullabledate.hasvalue ? nullabledate.value : dbnull.value;
but doesn't work either:
type saving countenance can't dynamic since there excellent reworking between 'system.datetime' 'system.dbnull'
but i don't wish modify between those types!
so distant wholly thing i work is:
if (nullabledate.hasvalue)
dateprm.value = nullabledate.value;
else
dateprm.value = dbnull.value;
is unequivocally wholly proceed i this? there proceed one-liner controlling ternary user work?
update: i don't unequivocally since ?? chronicle doesn't work. msdn says:
the ?? user advantage left-hand operand null, else advantage right operand.
that's accurately i want!
update2: good kind apparent end:
dateprm.value = nullabledate ?? (object)dbnull.value;
Comments
Post a Comment