Getting Error while executing SELECT statement in Toad for MySQL

余生颓废 提交于 2019-12-06 06:05:53

问题


I am getting this error while I am trying to execute a simple SELECT statement in Toad

 MySql.Data.Types.MySqlConversionException
 Unable to convert MySQL date/time value to System.DateTime

What could be wrong?


回答1:


That could mean one of these two common issues:

1) Zero dates, which are 0000-00-00 in MySQL. MySQL allows you to store them to mark 0 dates, you can even use 0001-01-01, but not all drivers or downstream programs can handle them. Add to the connection string

Allow Zero Datetime=true;

The other choice is explicitly removing them, something like

SELECT IF(DateCol='0000-00-00' OR DateCol<'1970-01-01', NULL, DateCol) as DateCol,
      Othercol1, ID ....
FROM TBL

2) Date formatting. For some driver/program combination, the dates are handled as strings. Explicit conversion is necessary:

SELECT DATE_FORMAT(DateCol, '%m/%d/%Y') as DateCol,
      Othercol1, ID ....
FROM TBL


来源:https://stackoverflow.com/questions/5088472/getting-error-while-executing-select-statement-in-toad-for-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!