The conversion of a varchar data type to a datetime data typ_MySQL

WBOY
Release: 2016-05-30 17:09:50
Original
1979 people have browsed it

刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME

执行时,它却发生了如标题提示的异常:

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

跟踪一下,当遇上一个空值时,它并没有真正是给一个空值给数据库,而是Datetime的最小值"1/1/0001 12:00:00 AM"

The conversion of a varchar data type to a datetime data typ_MySQL

在两个文本框都是空值时,跟踪如下:

The conversion of a varchar data type to a datetime data typ_MySQL

当这个值传入数居库时,数据库转换这个字符值为DateTime出错了:

试执行一下下面的SQL语句:

The conversion of a varchar data type to a datetime data typ_MySQL

经查资料,是因为DateTime数据类型的最小值为"1/1/1753 12:00:00 AM",如果想把"1/1/0001 12:00:00 AM"正确转换为日期时间,那得需要使用DATETIME2数据类型。
The conversion of a varchar data type to a datetime data typ_MySQL


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!