Unable to convert MySQL date/time value to System.DateTime

后端 未结 9 862
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 22:04

I am using ibatis and C#. i get a result from a select query that has CreatedDate as one of the field. The Datatype of CreatedDate in Mysql is Date. I assign the result set

相关标签:
9条回答
  • 2020-12-08 22:46

    It could be outside the range of a DateTime object. I've seen that a couple of times. Try changing the sql to return the current date instead of your column and see if it comes through ok.

    0 讨论(0)
  • 2020-12-08 22:48
    MySqlConnection connect = new MySqlConnection("server=localhost; database=luttop; user=root; password=1234; pooling = false; convert zero datetime=True");
    

    Adding convert zero datetime=True to the connection string will automatically convert 0000-00-00 Date values to DateTime.MinValue().

    that's SOLVED

    0 讨论(0)
  • 2020-12-08 22:49

    Adding "convert zero datetime=True" to the connection string solved my problem.

    <connectionStrings>   <add name="MyContext" connectionString="Datasource=localhost;Database=MyAppDb;Uid=root;Pwd=root;CHARSET=utf8;convert zero datetime=True" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
    

    Regards PS

    0 讨论(0)
提交回复
热议问题