3

I have a field DateTime for default its "null" but when my datatable try to read this field this is what happens

Não correspondência entre o tipo de valor e o tipo de colunaNão foi possível guardar ><01/01/0001 00:00:00> na coluna dh_cadastro. O tipo previsto é MySqlDateTime.

Mismatch between the type of value and type of column.Not possible be saved <01/01/0001 00:00:00> dh_cadastro column. The type expected is provided MySqlDateTime.

dmck
  • 7,801
  • 7
  • 43
  • 79
PlayHardGoPro
  • 2,791
  • 10
  • 51
  • 90
  • What is the valid datetime range in MySql? I know SQL Server's is not the same as System.DateTime. – Austin Salonen Aug 22 '12 at 19:03
  • I think that it might be caused by your default value - DateTime is a value type, so it can't be null. Try using DateTime.MinValue instead. – wlabaj Aug 22 '12 at 19:05
  • The value of `DateTime.MinValue` is different than MySQL's minimum representable `MySqlDateTime` value. You're seeing an error from the database, so you'd need to check against `MySqlDateTime.MinValue`. – Ted Spence Aug 22 '12 at 19:07

1 Answers1

1

If you are using null as a default value use a nullable DateTime object (DateTime?)

A regular DateTime cannot be null since it is a value type.

If you are getting errors with dates from the database, do a update to make sure there are no '0000-00-00' dates. Update these to be 0001-01-01 to align with .NET's DateTime.MinValue

Also see SqlDateTime.MinValue != DateTime.MinValue, why? for a review of the DateTime.MinValue issue between MySQL and .NET

Community
  • 1
  • 1
dmck
  • 7,801
  • 7
  • 43
  • 79
  • I Found out the error... The fields of birth_date are "0000-00-00" But when I ctrlC + CtrlV on it... when I past what I copy, its "24/12/2012, 25/04/2011"... Its normal dates... What the hell? I guess it's demonic stuff... any help ? Thanks – PlayHardGoPro Aug 22 '12 at 20:28