tags:

views:

366

answers:

4

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
I WANT TO ENTER NULL VALUE IN THE DATABASE IN INTEGER FIELDS IS THAT ANY OTHER WAY
KuldipMCA
Turn off your caps lock.
Troggy
@KuldipMCA: First things first, switch off the caps lock on your keyboard.
Naveen
+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
+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
ON THE BASIS OF MY VRIABLE ASSIGNING MY QUERY WILL BE GENERATED AUTOMATICALLY
KuldipMCA
Oh my. Dude, get a clue. Turn off the caps lock!
Troggy
ok i will turn of my caps lock sorry
KuldipMCA
Thank you. Everyone appreciates it.
Troggy
you are right i have to change the insert script for insert null in database
KuldipMCA
+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