无法将MySQL日期/时间值转换为System.DateTime C# [英] Unable to convert MySQL date/time value to System.DateTime C#

查看:267
本文介绍了无法将MySQL日期/时间值转换为System.DateTime C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此错误出现在这里



this error appear here

this.je_users_pendsTableAdapter.Fill(this.je_goDataSet.je_users_pends);





在插入新行时我使用datetime.now获取当前日期

mysql数据库中的日期值:( 0000-00-00)



连接字符串:





during inserting new row i use datetime.now to get the current date
value of date in the mysql database : (0000-00-00)

connection string :

//connectios
      public static string server = "localhost";
      public static string database = "jedb";
      public static string uid = "root";
      public static string password = "";

      public static string OPTION = "Convert Zero Datetime=True";

      public static string JGM_connStr = "SERVER=" + server + ";" + "DATABASE=" +
      database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";" + OPTION + ";";







一个想法?




an idea ?

推荐答案

如果您存储了00-00-0000日期值,(这是特殊零值 [ ^ ];或者你可以说DateTime的NULL值),那么你应该知道.NET框架的DateTime对象也有对DateTime值的限制,这可能是你的错误的原因。无论您是在从MySQL中提取值时将数据转换为适当的格式,您仍然必须确保数据根据.NET框架的验证规则有效。



If you're having 00-00-0000 date value stored, (Which is special zero value[^]; or you can say DateTime's NULL value), then you should know that .NET framework's DateTime object has a limitation over the DateTime value too, this might be the reason for your errors. No matter whether you convert the data to a proper format while extracting the values from MySQL, you still have to make sure that data is valid according to .NET framework's validation rules.

Quote:

DateTime值类型表示日期和时间,值范围从 00:00:00(午夜),0001年1月1日,Anno Domini(共同时代)公元9999年12月31日晚上11:59:59 公历

The DateTime value type represents dates and times with values ranging from 00:00:00 (midnight), January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) in the Gregorian calendar.





MSDN有资源 [ ^ ]。


DateTime rewardes_date = rewardes_dateDateTimePicker.Value.Date;


这篇关于无法将MySQL日期/时间值转换为System.DateTime C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆