.net - 数据集中的可空 Int 列

标签 .net int nullable strongly-typed-dataset

我正在使用 .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/

相关文章:

c# - Nullable Long switch 语句在 VS2015 中没有产生预期的输出

.net - 确定泛型参数是否为 Nullable 类型

c# - 为什么可以是int?设置为 null 有实例属性吗?

c# - 在JsonResult中返回文件还是在ActionResult中返回Json数据?

.net - 是否有类似于 Sql Server 表的 FileSystemWatcher 之类的东西?

go - 如何正确实例化 os.FileMode

python - 不使用 if 语句生成多个变量输出

c# - 使用 Aspose 在 .NET 中将 Excel、PowerPoint、PDF 和 Word 转换为图像

c# - 使用通用 LINQ 表达式调用 Contains 方法的忽略大小写

c - 在 Windows 上一个函数返回 int 到一个返回 BOOL 的函数是否重要?