3

I am using a MySQL database with DbLinq, but there is an exception being thrown:

"Cannot convert mysql datetime to system.datetime"

How can I resolve this issue?

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
pius
  • 31
  • 1
  • 2

4 Answers4

4

Check for any zero date means date like '0000-00-00' in database; this could be the cause of error.

John
  • 49
  • 1
  • 2
3

Either cast the MySqlDateTime as a DateTime or use mySqlDateTime.GetDateTime().

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
user239412
  • 31
  • 2
1

Well, if you have a result set containing MySql DateTime values, you could use the ConvertAll method along with a delegate using DateTime.Parse to create a collection of System.DateTime values.

Here's an example, where "results" is the result of your dblinq query containing MySQL datetime values:

List<DateTime> dateTimes = results.ConvertAll(delegate(string time){ 
   return DateTime.Parse(time); 
});

Is this what you're looking for?

Donut
  • 110,061
  • 20
  • 134
  • 146
1

I was moving a column in my gridview from asp:BoundField to asp:TemplateField so had to display a date from a MySQL database explicitly. I found, through reflection, that the collection typed the date fields as MySqlDateTime and not system.DateTime.

I added the import MySql.Data.Types statement to the code behind and the following Eval statement within a label in the context of a gridview.

Text='<%# CType(Eval("Submitted_Date"), MySql.Data.Types.MySqlDateTime).ToString%>'

output format: 02/23/2011

Hope that helps!

john plourd
  • 145
  • 1
  • 8