The DateTime.TryParse method takes a DateTime as an argument, not a DateTime? ?
Right now I have the following code:
if(!DateTime.TryParse(reader["Placed"].ToString(), out _placed)){
throw new Exception("Order's placed datetime could not be parsed.");
}
where _placed is of type
Nullable<DateTime> _placed = null;
What's a way around that?
How about this instead:
int x = reader.GetOrdinal("Placed");
if(!reader.IsDBNull(x))
_placed = reader.GetDateTime(x);
Just a combination of top answer and top comment. Thanks @Dylan-Meador and @LukeH.
(Ed. Note: For the long tail I think this version will save plenty of human time.)
int x = reader.GetOrdinal("Placed");
DateTime? _placed = reader.IsDBNull(x) ? (DateTime?)null : reader.GetDateTime(x);
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