我正在使用 .NET 强类型数据集,并且有一个带有可为空的 int 列(以及可为空的 DateTime 列)的表。
显然,数据集设计器存在一个错误,无法在这些数据类型上使用可为空的列。设计器只允许“抛出异常”作为空值的默认行为。不幸的是,在数据库中使用可为空的数据类型时,空值是合法值,但在尝试从数据行检索该值时会导致抛出异常。
我已经看到了几个关于这个问题的新闻组帖子,但还没有看到这个问题的任何体面的解决方法。
我很想听听其他人是如何处理这个问题的。
谢谢。
最佳答案
我认为 ASP.NET 论坛上的这篇文章将对这个问题有所帮助:
Strongly-Typed DataSet/Nullable column issue
The only way to set such properties to null is to use the helper methods that the dataset generator also creates. The methods are named after your column name, so in your case, you should have methods on the data row object called IsApprovingUserNull() and SetApprovingUserNull().
关于.net - 数据集中的可空 Int 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/879095/