无法将MySQL日期/时间值转换为System.DateTime

时间:2017-05-31 12:23:42

标签: mysql asp.net

当我运行我的应用程序时,我收到此错误...... !!

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:MySql.Data.Types.MySqlConversionException:无法将MySQL日期/时间值转换为System.DateTime

1 个答案:

答案 0 :(得分:0)

尝试使用IsDBNull()方法检查字段值是否为NULL,然后使用GetDateTime()

if (!reader.IsDBNull("FieldName")) {
    d = reader.GetDateTime("FieldName");
} else {
    d = ... ; /* set default value or do something to handle issue */
}

dDateTimereaderMySqlDataReader的位置。