Saturday, March 1, 2008

MySqlDateTime and .NET

In version 2008 our cross database comparison tool DBTyP.NET will support cross data comparison between SQL Server and MySQL DateTime values (date, datetime, smalldatetime). Actually, this is a common problem, between MySql.Data.Types.MySqlDateTime and System.DateTime types in .NET. It is very possible that if you tries to update MySqlDateTime column with DateTime variable you will get SystemArgumentException saying that could not store value ... into ... Expected type is MySqlDateTime. It is possible to format value as "yyyy-MM-dd HH:mm:ss" but in our case we don't want to iterate through whole DataSet and make this formatting.
Very elegant solution is to change a DataColumn type from MySqlDateTime to System.DateTime as

myMySqlDateTimeColum.DataType = typeof(System.DateTime);

After that you should not worry about formatting.

1 comment:

Hijo de la Luz said...

What if you are doing a read with MySqlDataReader? change the type is not an option in this circumstances