List:MySQL and .NET« Previous MessageNext Message »
From:Reggie Burnett Date:February 23 2005 2:01pm
Subject:RE: Date casting problem
View as plain text  
Correct James.

Kevin, I did include warnings and notices along the way that the behavior is
changing and will likely introduce a new connection string option to allow
for converting illegal datetimes to DateTime.MinValue.

The old ByteFX provider simple converted every illegal date that it saw to
DateTime.MinValue.  This certainly avoided any casting problems but then
reader.GetValue(x).ToString() on a column that has the value '0000-00-00'
would not return '0000-00-00' and many people saw this as a problem.  So
what do you do?

Regarding null datetime fields, those should work without trouble.  However
you need to keep in mind that when illegal or nullable datetimes are in the
mix, you cannot simply always convert to DateTime with something like
strDate = Ctype( dr("myDate"), Date).  You need to check that a column is
not null first.

My suggestion is that you make your date column allow nulls but never allow
illegal values such as 0000-00-00.  Then in your code you can do something
like

If reader.IsDBNull(x) then
   ... Handle my null case
Else
   strDate = Ctype( dr("myDate"), Date)
End if

-reggie 

> -----Original Message-----
> From: James Moore [mailto:banshee@stripped] 
> Sent: Sunday, February 13, 2005 12:29 PM
> To: 'Kevin Turner'; dotnet@stripped
> Subject: RE: Date casting problem
> 
> You probably want to take a look at the mailing list archives 
> for the discussions on this one over the last couple months.  
> The short answer is that it's difficult to define what the 
> correct behavior is; MySQL and .Net have different ideas of 
> what legitimate dates are and it's not clear that there's a 
> perfect way to reconcile them.  
> 
> - James
> 
> 
> --
> MySQL on .NET Mailing List
> For list archives: http://lists.mysql.com/dotnet
> To unsubscribe:    
> http://lists.mysql.com/dotnet?unsub=1
> 

Thread
Date casting problemKevin Turner13 Feb
  • RE: Date casting problemJordan Sparks13 Feb
RE: Date casting problemKevin Turner13 Feb
  • RE: Date casting problemJordan Sparks13 Feb
    • Re: Date casting problemBen Reichelt13 Feb
RE: Date casting problemKevin Turner13 Feb
  • RE: Date casting problemJames Moore13 Feb
    • RE: Date casting problemReggie Burnett23 Feb
  • Chasing a problem with an exception "Unable to write data to the transport connection"James Moore13 Feb
    • Re: Chasing a problem with an exception "Unable to write data to the transport connection"Jorge Bastos13 Feb
    • Re: Chasing a problem with an exception "Unable to write data tothe transport connection"Guy Platt12 Apr
      • Re: Chasing a problem with an exception "Unable to write data tothe transport connection"Guy Platt12 Apr
      • Re: Chasing a problem with an exception "Unable to write data to thetransport connection"SGreen12 Apr