Problems with DateTime types in SQL Server databases

Source: Internet
Author: User

We know that the datetime type in this SQL Server database is a data type that is often used in database application development, and the C # language also has a DateTime type, although both are used to describe time, but their default values are different, which must be noted in the development process , it is a waste of time to deal with the relationship between the two, which may cause unnecessary trouble, so remember. Let's take a look at:

Create a Windows application that creates a user information entity class UserInfo. Code as follows:

Note: The action Date property in the user information class is a date type.

Then create a business Operation class, Userinfooperate, with the following code:

Finally, create the form with the following code:

In the above code, there is no assignment to "operatedate" in the user information entity. Instead, the default value for the datetime type of C # is used.

When I click the Add button,

An exception occurred: a conversion from a char data type to a datetime data type resulted in a DateTime value being out of bounds.

(CTRL+D,Q) Fast monitoring, found that the value of Operatedate is: 0001-1-1 0:00:00.

In a SQL Server database, the value of the DateTime type must be: January 1, 1753 ~9999 December 31. The value of Operatedate in the above code is significantly less than 1753, 0001. So there was an error.

After I find the problem, I assign a reasonable value to its property.

Problems with DateTime types in SQL Server databases

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.