转换 DateTime 结果出现 IndexOutOfRangeException
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能意味着在阅读器中找不到它。
dr
是否有名为“Time”的列?It might mean that it can't be found in reader. Does
dr
have column with name "Time"?