开发者

Getting Error while executing SELECT statement in Toad for MySQL

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

 MySql.Data.Types.MySqlConve开发者_运维百科rsionException
 Unable to convert MySQL date/time value to System.DateTime

What could be wrong?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜