Unable to convert MySQL date/time value to System.DateTime

Ankit Chauhan picture Ankit Chauhan · Apr 22, 2011 · Viewed 131.3k times · Source

I get this error:

Unable to convert MySQL date/time value to System.DateTime

while I am trying to fetch the data from a MySQL database. I have the date datatype in my MySQL database. But while retrieving it into my datatable, it get the error above.

How can I fix this?

Answer

agni picture agni · Jun 27, 2012

You must add Convert Zero Datetime=True to your connection string, for example:

server=localhost;User Id=root;password=mautauaja;Persist Security Info=True;database=test;Convert Zero Datetime=True