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
精彩评论