Date error with MySQL and .NET
Sample query to retrieve a date from mysql and use it directly with a dataset, datatable, datagridview.
To convert the date in .net
when we wan to retrieve and add the date in the db.
A workaround in mysql is to set those vars for the session. It's not suggested and sometimes the variables are read only.
SET SESSION date_format="%Y/%m/%d";
SET SESSION datetime_format="%Y/%m/%d %H:%i:%s";
Mysql Exception MySql.Data.Types.MySqlConversionException' in MySql.Data.dll
Note: Info are a bit messed up
Sample query to retrieve a date from mysql and use it directly with a dataset, datatable, datagridview.
Select DATE_FORMAT(mysqldatecolumn, '%Y-%m-%d' ) from mytable
To convert the date in .net
convert.ToDateTime(MyVariableWithDate).ToString("yyyy-MM-dd")
Datetime.Now().ToString("yyyy/MM/dd hh:mm:ss")
when we wan to retrieve and add the date in the db.
A workaround in mysql is to set those vars for the session. It's not suggested and sometimes the variables are read only.
SET SESSION date_format="%Y/%m/%d";
SET SESSION datetime_format="%Y/%m/%d %H:%i:%s";
Mysql Exception MySql.Data.Types.MySqlConversionException' in MySql.Data.dll
Note: Info are a bit messed up
Comments
Post a Comment