Bug #29343 | Exception on GetDateTime() when reading 0000-00-00 00:00:00 Date field | ||
---|---|---|---|
Submitted: | 25 Jun 2007 17:33 | Modified: | 15 Aug 2007 12:42 |
Reporter: | Kevin Bilbee | Email Updates: | |
Status: | No Feedback | Impact on me: | |
Category: | Connector / NET | Severity: | S2 (Serious) |
Version: | 5.1.2 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[25 Jun 2007 17:33]
Kevin Bilbee
[2 Jul 2007 17:02]
Tonci Grgin
Hi Kevin and thanks for your report. Can you please submit standalone test case, including DDL statements. I am interested in your connection string in particular.
[10 Jul 2007 22:07]
Kevin Bilbee
How do I submit a standalone test case? I am new to bur reporting on the MySql site. Please assist.
[11 Jul 2007 6:50]
Tonci Grgin
Kevin, go to Files tab and browse for test case on your machine (or zip file etc.). Then click "Add file". Please put everything of importance inside your test case (tables, data ...) and make sure it fails whenever you run it.
[13 Jul 2007 22:27]
Kevin Bilbee
Due to time constraints instead of uploading files I will detail the steps to recreate here. This is from a asp .net c# application. Create a MySql table MyISAM with a DateTime field. We are running 4.1.x on the server I have been testing against, I did not test against 5.0.x. In MS SQL you can add date parameter to a command as a string and it will do the conversion for you. This is where my mistake started. When running the following parameter is added to the MySqlCommand, txtWWWEndDate.Text has a properly formatted Date 7/2/2007 myCommand.Parameters.AddWithValue("?WWWEndDate", txtWWWEndDate.Text); There is no error thrown and the data placed into the database is 0000-00-00 00:00:00. And when reading the resulting date time you get the origional error message posted, here is the code I was trying to use to read the DateTime field if (!lreader.IsDBNull(7)) { txtWWWStartDate.Text = lreader.GetDateTime(7).ToShortDateString(); } When using this code to place a date into the DateTime field I figured out the MySQlcommand likes the following code myCommand.Parameters.AddWithValue("?WWWEndDate", Convert.ToDateTime(txtWWWEndDate.Text)); The date is properly placed into the database and retreiving the value it is no problem. It seems to me that when reading a DateTime field my the MySql connector attempts to convert the database value to a dotnet DateTime object. But when creating the parameter it does not attempt to convert the value presented to a DateTime object. I hope this helps. I hve been placed on a large time constrained project and will not be able to revisit this issue for a while.
[15 Jul 2007 12:42]
Tonci Grgin
Kevin, I will still need some more info from you, so please revisit when time allow: - This behavior is server dependent in terms of SQL mode used - pls attach My.ini file - This behavior is c/NET dependent in terms of connection properties: Allow Zero Datetime false True to have MySqlDataReader.GetValue() return a MySqlDateTime for date or datetime columns that have illegal values. False will cause a System.DateTime object to be returned for legal values and an exception will be thrown for illegal values. Convert Zero Datetime false True to have MySqlDataReader.GetValue() and MySqlDataReader.GetDateTime() return Date- Time.MinValue for date or datetime columns that have illegal values. - pls attach full test case
[15 Aug 2007 23:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".