【问题标题】:MySql Null DateTime and MS.net are not playing niceMySql Null DateTime 和 MS.net 玩得不好
【发布时间】:2010-09-25 23:02:32
【问题描述】:

问题来了。

我有一个包含日期的表(mySQL),其中一些为空。 我知道我可以使用 DateTime?或 Nullable 以允许空值,但我不确定在哪里设置它。

我尝试过的:

我在 dblm.日期属性具有以下属性集:

Nullable : True
Server Data Type : DateTime
Type : NUllable<DateTime>

这些设置允许构建我的代码。 当我调试它时抛出这个异常: System.NullReferenceException:对象引用未设置为对象的实例..

如果我尝试使用这些属性:

Nullable : True
Server Data Type : NUllable<DateTime>
Type : NUllable<DateTime>

我得到了与上面相同的异常。

其他无效的方法:

Nullable : True
Server Data Type : DateTime?
Type : NUllable<DateTime>

Nullable : True
Server Data Type : DateTime?
Type : DateTime?

我正在使用 .net 的 3.5 框架

谢谢

【问题讨论】:

  • 显示抛出异常的代码。

标签: mysql .net datetime linq-to-sql null


【解决方案1】:

固定 - 原来是连接到 mySQL DB 的连接字符串存在问题。

我也不知道可以使用服务器资源管理器将表拖放到 DBML 中。我需要做的就是连接到数据库,然后将表放到 DBML 上。

【讨论】:

    【解决方案2】:

    我记得有一个problem 带有 mysql 的 ADO.NET 驱动程序,它在使用空日期/时间字段时根本不适合。

    甚至 IsDBNull 也会在日期/时间为空的字段上引发异常。

    这可能仍然是个问题。

    【讨论】:

      猜你喜欢
      • 2011-06-15
      • 2019-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 2015-07-06
      • 2022-08-21
      相关资源
      最近更新 更多