Bug #7132 Inserting DateTime causes System.InvalidCastException to be thrown
Submitted: 9 Dec 2004 15:26 Modified: 31 Jan 2005 21:19
Reporter: Arthur Ouwerkerk Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.2-gamma OS:Microsoft Windows (Windows XP)
Assigned to: Reggie Burnett CPU Architecture:Any

[9 Dec 2004 15:26] Arthur Ouwerkerk
When inserting a row which contains a DateTime-field, updating will throw a System.InvalidCastException 
(System.InvalidCastException: Specified cast is not valid.
   at System.Convert.ToDateTime(Object value)
   at System.Data.Common.DateTimeStorage.Set(Int32 record, Object value)
   at System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store <9-12-2004> in InleesDatum Column.  Expected type is DateTime.)

This worked fine with the previous version of MySqlConnector .Net.

The row that was being updated will actually be inserted, but once the exception is thrown it won't insert any subsequent rows that might be in the dataset

How to repeat:
-Create a mysql database containing a table with a single DateTime-column
-Write a simple C# program, including a Typed Dataset, which mirrors the mysql table
-Use MySqlCommandBuilder to generate the insert command for a MySqlDataAdapter
-Insert a new row in the dataset with value DateTime.Now
-Update the dataset using the MySqlDataAdapter
-Now the exception shown before will be thrown
[9 Dec 2004 15:39] Arthur Ouwerkerk
I've added a sample project to repeat the problem (see 'files')
[10 Dec 2004 18:17] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at

Additional info:

I wasn't able to directly reproduce this but I changes how datetimes are handled  so I'm marking it fixed instead of can't repeat.

If you want, when 1.0.3 hits the street, check out the InsertDateTimeValue method in the DateTimeTests.cs file in the test suite.  It will show you how I am testing this.