c# - No overload for method 'ToString" takes 1 arguments when casting date -


i trying save date angular ui-datepicker sql database. date in format (10-27-2015 12:00 am) not save. tried using following convert sql datetime format:

    datetime? mydate = form.dtestartdate;     string sqlformatteddate = mydate.tostring("yyyy-mm-dd hh:mm:ss"); 

but receive error "no overload method 'tostring' takes 1 arguments. field in sql type 'datetime'.

any assistance appreciated.

you want use datetime.tostring(format) not nullable<datetime>.tostring(no overload):

datetime? mydate = form.dtestartdate; string sqlformatteddate = mydate.value.tostring("yyyy-mm-dd hh:mm:ss"); 

of course doesn't handle case there no value. perhaps this:

string sqlformatteddate = mydate.hasvalue      ? mydate.value.tostring("yyyy-mm-dd hh:mm:ss")     : "<not available>"; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -