How to solve SqlDateTime overflow and sqldatetime Overflow

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.