Can Nullable Types be used in VB.NET? If so, is it possible to have a Nullable Integer that I can use with a field that accepts NULL in SQL Server? Examples would be appreciated.
+4
A:
You can't assign Null
, Nothing
or DBNull
to an integer in VB. You can use a Nullable(Of Integer)
instead to accomplish that, or box the integer value in an Object
(which can be Nothing
).
Konrad Rudolph
2009-07-14 06:59:22
I WANT TO ENTER NULL VALUE IN THE DATABASE IN INTEGER FIELDS IS THAT ANY OTHER WAY
KuldipMCA
2009-07-14 07:01:22
Turn off your caps lock.
Troggy
2009-07-14 07:02:16
@KuldipMCA: First things first, switch off the caps lock on your keyboard.
Naveen
2009-07-14 07:03:13
+2
A:
Integers (System.Int32
etc) in .NET are not directly nullable; however, there is Nullable-of-T
that allows you to make any value-type nullable-ish. Note that you may have to check the database against DBNull
rather than null
/Nothing
.
So yes, you can do something very similar.
Marc Gravell
2009-07-14 07:00:20
+1
A:
Nope. You will have to modify the insert or update query to not add (or update) that value to get a null in the database.
Craig
2009-07-14 07:03:47
+1
A:
VB.Net does have nullable types, they can be declared in the following two different ways.
Dim iNullable As Integer?
or
Dim iNullable As Nullable(Of Integer)
Stevo3000
2009-07-14 07:56:11