Convert MySQL DATETIME to System.DateTime

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

"Unable to convert mysql datetime to System.DateTime"

How can I solve this problem?

+2


source to share


4 answers


Check if the date is zero date like '0000-00-00' in the database; this could be the cause of the error.



+5


source


Well, if you have a result set containing MySql values DateTime

, you can use the method ConvertAll

along with a delegate DateTime.Parse

to create a collection of the System.DateTime

value.

Here is an example where "results" are 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 are looking for?

+1


source


+1


source


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

I added the import operation MySql.Data.Types to the code behind and the following Eval statement on the label in the gridview context.

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

output format: 02/23/2011

Hope it helps!

+1


source







All Articles