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