Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

RE: Nullable(Of Integer) question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BobRoyAce - 20 Mar 2008 01:15 GMT
I am new to Nullable types.

Let's say that I have a variable as follows:

Dim iID As Nullable(Of Integer)

Now, let's say that I have code that either needs to assign an integer
value to iID or have it be NULL. For simplicity, let's use...

If (True) Then
 iID = 12
Else
 iID = Nothing
End If

At this point, if iID = Nothing was executed, iID = 0 and iID.HasValue
returns True! What do I assign to iID such that iID.HasValue will
return False?
Armin Zingler - 20 Mar 2008 01:31 GMT
> I am new to Nullable types.
>
[quoted text clipped - 15 lines]
> iID.HasValue returns True! What do I assign to iID such that
> iID.HasValue will return False?

Can't reproduce it. After assigning Nothing, iId.Hasvalue returns false.

Armin
BobRoyAce - 20 Mar 2008 01:50 GMT
Oops...I figured out what the problem was. I was assigning the value
via a function that was returning an Integer. In certain
circumstances, I was returning Nothing, which ultimately returned ZERO
(0). I just had to change the function so that it returned a
Nullable(Of Integer). Silly me...
Cor Ligthert[MVP] - 20 Mar 2008 06:58 GMT
Bob,

I am always curious why people will use what you are doing, a nullable
integer is in fact a worse thing from the past.

What is your reason?

(Be aware that a integer that is null, has nothing to do with the value type
DBNull.Value which can be inside an object)

Cor

>I am new to Nullable types.
>
[quoted text clipped - 14 lines]
> returns True! What do I assign to iID such that iID.HasValue will
> return False?
Patrice - 20 Mar 2008 19:31 GMT
This is for example used in LINQ to SQL to handle nullable columns. Yes I
know this is not the same thing but just a "representation", I believe we
already had this discussion without understanding much each other....

Likely more usefull for date columns as they can usually hold a date for a
future event in which case those columns are made nullable than for any
other data type...

--
Patrice

> Bob,
>
[quoted text clipped - 7 lines]
>
> Cor
BobRoyAce - 20 Mar 2008 20:50 GMT
> Bob,
>
> I am always curious why people will use what you are doing, a nullable
> integer is in fact a worse thing from the past.
>
> What is your reason?

I use Nullable(Of Integer) for variables that will store foreign key
references to other tables. So, let's say that I have a class called
LoanApplication, with a property called fkDeclinedByUserID. This
property must either be NULL, or have an integer value corresponding
to the primary key field of a User record. In my code that does the DB
update or insert, I check to see if fkDeclinedByUserID.HasValue is
True. If it is, I pass in the integer to the stored procedure
parameter; otherwise, I pass in System.Convert.DBNull.
Etxe - 20 Mar 2008 23:32 GMT
I use a table whith a field that is relation whith another table

I use a from with textboxs binding to a dataset

When I want to clear the value of this field it receive the "" value and it
can be save in the bd because the relational table not have "" record,

I need to give null value before update the record, how can i do?

Thanks

Sorry my English

>> Bob,
>>
[quoted text clipped - 11 lines]
> True. If it is, I pass in the integer to the stored procedure
> parameter; otherwise, I pass in System.Convert.DBNull.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.