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?

2
  • How are you casting/converting it now? Commented Dec 28, 2009 at 5:56
  • Is the MySql date a unix timestamp? Commented Jan 30, 2010 at 16:32

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

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?

Comments

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.