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 resolv开发者_如何学Ce this issue?
Check for any zero date means date like '0000-00-00' in database; this could be the cause of error.
Either cast the MySqlDateTime
as a DateTime
or use mySqlDateTime.GetDateTime()
.
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?
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!
精彩评论