问题
I have a table that holds system users with their last login date and time in it. The admin users of the system need to be able to add users, but when I add the new user record a validation error occurs unless I put a valid datetime in the last login date field.
I've tried manually changing the field to dbnull, null, etc prior to the save but it says those values cannot be converted to datetime. The column does allow nulls in the db.
Any suggestions?
回答1:
If you set LastLogin to be DateTime? then you can pass null to the DB without failure.
回答2:
Can you alter the table structure? If so, you can define a default value like "1970.01.01", for example.
来源:https://stackoverflow.com/questions/975457/subsonic-3-asp-net-mvc-trying-to-save-a-null-value-in-a-datetime-column