Change uncertainty to confirmation ~ DateTime. MinValue and MaxValue exceptions

Source: Internet
Author: User

Back to directory

Problem description: Concept-related

. The MinValue and MaxValue in the DateTime structure class in. Net sometimes cause an exception, that is, the date overflow problem. The date you enter must be between January 1, and DateTime. minValue is not January 1, 1753, but January 1, 0000, and the minimum datetime value that the database can receive is 1753/1/1.. net. minValue is much smaller than it, so it has a date overflow problem.

Solve the problem

Let's perform a test:

 

The result is:

Therefore, if you want to query the date in the database in a program, if you want to give the date variable a default value, DateTime is not used. minValue, which is located in System. data. the SqlTypes namespace indicates the data type corresponding to SQLSERVER. The test code is as follows:

 

The result is:

It is embodied in the program:

??? =] = Specification = model = userManager. GetWebManageUsers (specification, PageParameters (page ?? , = PartialView (

In the code above, the DateTime type can be replaced by the SqlDateTime type because it is related to database queries!

Back to directory

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.