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.
You can declare nullable types using Nullable<t> where T is a type. Nullable<int> i = null; A nullable type can represent the correct range of values for its underlying value type, plus an additional null value. For example, Nullable<int> can be assigned any value from -2147483648 to 2147483647, or a null value.
For writable tables, any column that is going to store an SQL NULL value must have a null condition-name. If you have a table with multiple record types, it is possible to mark columns as nullable without an underlying null condition-name.
Nullable types are neither value types nor reference types. They are more like value types, but have a few properties of reference types. Naturally, nullable types may be set to null . Furthermore, a nullable type cannot satisfy a generic struct constraint.
The Nullable type allows you to assign a null value to a variable. Nullable types introduced in C#2.0 can only work with Value Type, not with Reference Type. The nullable types for Reference Type is introduced later in C# 8.0 in 2019 so that we can explicitly define if a reference type can or can not hold a null value.
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With