转换 DateTime 结果出现 IndexOutOfRangeException

发布于 2024-11-14 12:56:46 字数 455 浏览 12 评论 0原文

Time =(DateTime) AllQuestionsPresented.TryParse(dr["Time"].ToString());

其中 dr 是 SqlReader。

我收到 IndexOutOfRangeException,但我不知道为什么。这是 TryParse 函数:

public static DateTime? TryParse(string text)
{
    DateTime date;
    if (DateTime.TryParse(text, out date))
    {
        return date;
    }
    else
    {
        return null;
    }
}

我不明白为什么会出现该异常以及如何摆脱它?!

Time =(DateTime) AllQuestionsPresented.TryParse(dr["Time"].ToString());

Where dr is a SqlReader.

I get an IndexOutOfRangeException and I don't know why. Here is the TryParse function:

public static DateTime? TryParse(string text)
{
    DateTime date;
    if (DateTime.TryParse(text, out date))
    {
        return date;
    }
    else
    {
        return null;
    }
}

I don't understand why I get that exception and how could i get rid of it?!

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

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

发布评论

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

评论(1

醉酒的小男人 2024-11-21 12:56:46

这可能意味着在阅读器中找不到它。 dr 是否有名为“Time”的列?

It might mean that it can't be found in reader. Does dr have column with name "Time"?

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