I have a MS SQL Local DB which allows a column fields to have null values. However, when I tried to set (DateTime?) null to the field, there was an exception "System.ArgumentException Cannot set Column 'DeliveryTime' to be null. Please use DBNull instead.". So i tried replacing (DateTime?) null to DBNull.value. Then a compile error popped up
"CS0173 C# Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DateTime' and 'System.DBNull'"
I'm using MS VS 2017 community. What shall I do about this?
DataRow row;
string rs;
DateTime dt;
row["DeliveryTime"] = DateTime.TryParse(rs, out dt) ? dt : (DateTime?) null;
// I replaced (DateTime?) null to DBNull.Value and got a compile error