类型化数据集 - InvalidCastException
我有一个类型化的数据集。我使用绑定源将数据绑定到包含大约 200 个文本框、数据编辑等的表单。一切正常,但有一个例外:
在我的数据库中,我有空的 DateTimes (DBNull.Value)。当它们绑定到 DateEdit-Control 时,我遇到以下异常:
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.Data.StrongTypingException' occurred in myTestDLL.dll
我尝试将 DataSet-Desinger 中的 NullValue-Property 更改为“抛出异常”等其他内容,但它不适用于 DateTime。对于其他类型(例如整数或字符串),它工作得很好。
我不知道一个好的解决方案(现在我用一些虚拟日期填充空日期并使其在 DateEdit-Control 中不可见,但这非常不酷),我希望在这里找到一些帮助。
看来很多人都遇到了同样的问题,但我没有找到解决方案:(
I've got a typed dataset. I bind the data with a binding source to a form with arround 200 textboxes, dataedits and so on. Everything works fine with one exception:
In my database I have empty DateTimes (DBNull.Value). And when they get bound to a DateEdit-Control, I get the following exceptions:
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.Data.StrongTypingException' occurred in myTestDLL.dll
I tried to change the NullValue-Property in the DataSet-Desinger to something else as 'Throw Exception', but it doesn't work for a DateTime. For other types like Integer or String it works fine.
I dont know a nice solution (right now I fill the empty dates with some dummy date and make it invisible in the DateEdit-Control, but this is very uncool) and I hope to find some help here.
It seems that many people got the same problem but I didn't find a solution :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果测试失败为什么不直接跳过呢?
Why not just skip if test fail ?