如何处理来自 SQL Server 的 DBNull DateTime 字段?

发布于 2024-07-29 21:38:59 字数 160 浏览 2 评论 0原文

当我检索包含空 DataTime 字段的行时,出现此错误:

“srRow.Closed_Date”引发了“System.Data.StrongTypingException”类型的异常

我如何正确处理这些异常?

I am getting this error when I retrieve a row with a null DataTime field:

'srRow.Closed_Date' threw an exception of type 'System.Data.StrongTypingException'

How do I properly handle these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可可 2024-08-05 21:39:02

假设您使用 .NET,则有 SqlTypes 可以在这样的情况下使用。

Assuming you're using .NET, there are SqlTypes that can be used in a situation like this.

度的依靠╰つ 2024-08-05 21:39:01

此处有一个参考。

或者,您是否可以使用 IsNull 运算符修改查询以确保结果不为空?

Select (IsNull, SomeDateField, GetDate())

There's a reference here.

or possibly, can you modify your query to ensure the results are not null by using the IsNull operator?

Select (IsNull, SomeDateField, GetDate())
窗影残 2024-08-05 21:39:01

您可以在检索该值之前检查该列中是否有空值。

if (!srRow.IsClosed_DateNull())
{
  myDate = srRow.Closed_Date;
}

You can check for a null value in that column before retrieving the value.

if (!srRow.IsClosed_DateNull())
{
  myDate = srRow.Closed_Date;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文