Nullable Int Column in DataSet

goombaloon picture goombaloon · May 18, 2009 · Viewed 11.4k times · Source

I'm working with .NET strongly-typed datasets and have a table with a nullable int column (and a nullable DateTime column as well).

Apparently there is a bug with the dataset designer that prevents having nullable columns on these data types. The designer only allows "throw exception" as the default behavior for null values. Unfortunately, when using a nullable data type in the database, a null value IS a legitimate value but results in a thrown exception when attempting to retrieve this value from a data row.

I've seen several newsgroup postings about this problem but have yet to see any decent workarounds to this issue.

I'd love to hear how others have dealt with this problem.

Thanks.

Answer

Gabriel Chung picture Gabriel Chung · Jun 1, 2009

I think this post on ASP.NET forum will be some help for the question: 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().