How to solve SqlDateTime overflow and sqldatetime Overflow
Error:"SqlDateTime overflow occurs during data import. It must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM ."
This problem occurs mostly because the datetime field value is null when you insert or update the database. By default, January 01, 0001 is inserted, resulting in the datetime type overflow.
Cause analysis:
About DateTime, the most common error when inserting DateTime type into the database is "SqlDateTime overflow. It must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. "The reason is that we are taking DateTime. when the value of MinValue is inserted into the database, DateTime. the value range of MinValue is inconsistent with that of DateTime data in the database. In the database, the DateTime type field, minimum value 1/1/1753 12:00:00, and.. NET Framework, DateTime type, minimum value: 1/1/0001 0:00:00, apparently, beyond the minimum range of SQL values, leading to data overflow errors.
Solution:
Use System. Data. SqlTypes. SqlDateTime. MinValue to replace the System. DateTime type. In this way, the MinValue of SqlDateTime is consistent with the DateTime range in SQL, and the preceding error will no longer occur.
However. data. sqlTypes. sqlDateTime. minValue is assigned to System. the following error occurs for DateTime type variables: Error 86: The type "System. data. sqlTypes. sqlDateTime is implicitly converted to System. dateTime ". There is an explicit conversion (is forced conversion missing ?) We can use Convert. ToDateTime for forced conversion.
Appendix: The default DateTime value of the SQLServer database is 00:00:00. If the null value is inserted, the default value is 00:00:00.