473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How Can an Integer Contain a Null Value?

TC
What does it mean for an integer to have a null value? I am trying to use
the DataView.Find method. That method has an integer return type which
contains the "index of the row in the DataView containing the sort key value
specified; otherwise a null value if the sort key value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects could
evaluate to System.DBNull.) How can I test whether an integer variable holds
a null value?
-TC
Nov 20 '05 #1
15 29163
Cor
Hi TC,
What does it mean for an integer to have a null value? I am trying to use
the DataView.Find method. That method has an integer return type which
contains the "index of the row in the DataView containing the sort key value specified; otherwise a null value if the sort key value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects could
evaluate to System.DBNull.) How can I test whether an integer variable holds a null value?


My first thought of the answer was a value can never be "nothing" or
"dbnull".

(This is dangerous stuff, because I once had an argue here about what is
difficult about English language and then I said by instance the definition
of words like null.)

So don't look to much on the words I use, just at the meaning.

But then I saw that you are probably talking about a database integer, what
is a total different thing. It is a placeholder for an integer. That can be
empty or dbnull

Just beneath your message you see a message with executeScalar.

Sthephany did send yesterday an example for drygast how to use that. I saw
it yesterday too the first time for the answer beneath I don't know if it
fit. For you I think it does.

I pasted it in beneath

\\\
You are using a reader and that will have a record if it exist and it will
have no records if it does not exist. Your issue is with the fact that you
are not handling the situation when the reader has no records.

Change track a little and use ExecuteScalar() against the command object
with the sql changed to:

select count(*) from [order] where ordernummer=" & txtOrdernummer.Text

The result will be 1 if the order exists and 0 if it does not.

So the test becomes:

If cmd.ExecuteScalar() = 0 Then
' Order does not exist
Else
' Order does exist
End If
///
I hope this helps a little bit.

Cor
Nov 20 '05 #2
"TC" <q@w.e> schrieb
What does it mean for an integer to have a null value? I am trying to
use the DataView.Find method. That method has an integer return type
which contains the "index of the row in the DataView containing the
sort key value specified; otherwise a null value if the sort key
value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects
could evaluate to System.DBNull.) How can I test whether an integer
variable holds a null value?


The word "null" can have two different meanings depending on the context. In
the Framework and for the CLR (docs), Null is the term for "no reference".
The equivalent term in VB.NET is Nothing. When talking about "Null" in a
database, it means DBNull (resp. DBNull.Value). It might get confusing when
you get a message from the framework that deals with database stuff. In this
case, we have to be clever enough to recognize what is meant by the word
"Null".

Talking in the VB.NET context: An Integer variable can neither be Nothing
nor it can be DBNull. (in a C# context I'd have to say: An Integer variable
can neither be Null nor it can be DBNull). Whenever the variable is related
to a database value and it can be DBNull or an Integer, the type must be
"Object". Only variables declared as Object can either contain DBNull or a
(boxed) Integer. You can not set an Integer variable to DBNull (you could
set it to Nothing, but that's equal to setting it to zero (and actually it
should not be allowed because it's only confusing)). If the variable is
declared as Object, you can use

If theValue Is DBNull.VAlue then
msgbox "database field contains Null"
else
msgbox theValue
end if

The first msgbox could also show
msgbox "database field contains DBNull"
but in the given context ("database field...") it's sufficient to show
"Null" in the message.
--
Armin

Nov 20 '05 #3
TC,
In addition to the others comments.

According to David Sceppa's book "Microsoft ADO.NET - Core Reference" from
MS Press, DataView.Find returns -1 if the desired row is not found. Which is
consistent with other similar searching type methods found in the framework.

Running a quick test confirms that DataView.Find returns a -1 when the key
is not found.

If you are using ADO.NET, I would recommend David's book.

Hope this helps
Jay

"TC" <q@w.e> wrote in message news:W5Mib.4869$iq3.1202@okepread01...
What does it mean for an integer to have a null value? I am trying to use
the DataView.Find method. That method has an integer return type which
contains the "index of the row in the DataView containing the sort key value specified; otherwise a null value if the sort key value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects could
evaluate to System.DBNull.) How can I test whether an integer variable holds a null value?
-TC

Nov 20 '05 #4
TC
Cor,

Thank you for the reply. In fact, I was asking about a system integer, not a
database integer. It seems that the problem arises from incorrect/ambiguous
syntax in the VB.NET documentation. Instead of saying the Find method
returns an integer "null value", the documentation should say it returns the
value -1.

-TC
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi TC,
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which
contains the "index of the row in the DataView containing the sort key value
specified; otherwise a null value if the sort key value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects could evaluate to System.DBNull.) How can I test whether an integer variable

holds
a null value?


My first thought of the answer was a value can never be "nothing" or
"dbnull".

(This is dangerous stuff, because I once had an argue here about what is
difficult about English language and then I said by instance the

definition of words like null.)

So don't look to much on the words I use, just at the meaning.

But then I saw that you are probably talking about a database integer, what is a total different thing. It is a placeholder for an integer. That can be empty or dbnull

Just beneath your message you see a message with executeScalar.

Sthephany did send yesterday an example for drygast how to use that. I saw
it yesterday too the first time for the answer beneath I don't know if it
fit. For you I think it does.

I pasted it in beneath

\\\
You are using a reader and that will have a record if it exist and it will
have no records if it does not exist. Your issue is with the fact that you
are not handling the situation when the reader has no records.

Change track a little and use ExecuteScalar() against the command object
with the sql changed to:

select count(*) from [order] where ordernummer=" & txtOrdernummer.Text

The result will be 1 if the order exists and 0 if it does not.

So the test becomes:

If cmd.ExecuteScalar() = 0 Then
' Order does not exist
Else
' Order does exist
End If
///
I hope this helps a little bit.

Cor

Nov 20 '05 #5
TC
Armin,
The word "null" can have two different meanings depending on the

context...

It seems that the word "null" can have a third meaning too. In the online
documentation for the TreeView.Find method, "null value" apparently means
the integer value -1.

-TC
Nov 20 '05 #6
TC
Jay,

Thank you. That solves the mystery.

-TC
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
TC,
In addition to the others comments.

According to David Sceppa's book "Microsoft ADO.NET - Core Reference" from
MS Press, DataView.Find returns -1 if the desired row is not found. Which is consistent with other similar searching type methods found in the framework.
Running a quick test confirms that DataView.Find returns a -1 when the key
is not found.

If you are using ADO.NET, I would recommend David's book.

Hope this helps
Jay

"TC" <q@w.e> wrote in message news:W5Mib.4869$iq3.1202@okepread01...
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which
contains the "index of the row in the DataView containing the sort key

value
specified; otherwise a null value if the sort key value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects could evaluate to System.DBNull.) How can I test whether an integer variable

holds
a null value?
-TC

Nov 20 '05 #7
"TC" <q@w.e> schrieb
Armin,
The word "null" can have two different meanings depending on the

context...

It seems that the word "null" can have a third meaning too. In the
online documentation for the TreeView.Find method, "null value"
apparently means the integer value -1.


To me it seems to be a documentation fault.
--
Armin

Nov 20 '05 #8

Actually the .NET Framework don't let you set Null
(Nothing in VB) to an int, a bool, a DateTime, etc.

So BCL functions cannot return Null value for built-in
types.

If you need to set Null (Nothing in VB) to an int, a bool,
a DateTime, ... you can use NullableTypes:
http://nullabletypes.sourceforge.net/

bye (luKa)
Nov 20 '05 #9
Luca,
Actually the .NET Framework don't let you set Null
(Nothing in VB) to an int, a bool, a DateTime, etc. However! VB.NET treats Nothing as the default value for any type.

<blockquote>
Nothing is a special literal; it does not have a type and is convertible to
all types in the type system. When converted to a particular type, it is the
equivalent of the default value of that type.
</blockquote>

http://msdn.microsoft.com/library/de...BSpec2_4_7.asp

In other words, if you assign Nothing to an Integer that integer is set to
the 'default' value for an Integer which is Zero!

Try it!
Dim i as Integer = Nothing
Dim b As Boolean = Nothing
Dim c As Char = Nothing
Dim pt As Point = Nothing

If you run the above you will find each value has the defaults for that
value. (0, False, Char.MinValue (which the debugger displays as Nothing)).
Seeing as Point is a structure, the default for Point is the default for
each of its members, in other words pt.x = 0 & pt.y = 0.

Hope this helps
Jay
"Luca Minudel" <an*******@discussions.microsoft.com> wrote in message
news:2b*****************************@phx.gbl...
Actually the .NET Framework don't let you set Null
(Nothing in VB) to an int, a bool, a DateTime, etc.

So BCL functions cannot return Null value for built-in
types.

If you need to set Null (Nothing in VB) to an int, a bool,
a DateTime, ... you can use NullableTypes:
http://nullabletypes.sourceforge.net/

bye (luKa)

Nov 20 '05 #10
-----Original Message-----
Luca,
Actually the .NET Framework don't let you set Null
(Nothing in VB) to an int, a bool, a DateTime, etc.However! VB.NET treats Nothing as the default value for

any type.
Hope this helps
Jay
"Luca Minudel" <an*******@discussions.microsoft.com> wrote

If you need to set Null (Nothing in VB) to an int, a bool,
a DateTime, ... you can use NullableTypes:
http://nullabletypes.sourceforge.net/


Nov 20 '05 #11
Luca,
??

Did you have something to say? As all I see is an empty trimmed message!

Thanks
Jay

"Luca Minudel" <an*******@discussions.microsoft.com> wrote in message
news:35****************************@phx.gbl...
-----Original Message-----
Luca,
Actually the .NET Framework don't let you set Null
(Nothing in VB) to an int, a bool, a DateTime, etc.

However! VB.NET treats Nothing as the default value for

any type.

Hope this helps
Jay
"Luca Minudel" <an*******@discussions.microsoft.com> wrote

If you need to set Null (Nothing in VB) to an int, a bool,
a DateTime, ... you can use NullableTypes:
http://nullabletypes.sourceforge.net/

Nov 20 '05 #12
Here it is! -

Yes this help! I'm primarely a C# programmer so I made
some confusion about Nothing in VB.

What I meant is that NullableTypes let you set Null to an
int, a bool, a DateTime and to quite any built-in .NET
type. But Null is not the default value and it is not
Nothing. It's a different value and it is strong typed
(i.e. Null for a DateTime is different from a Null for a
bool).

I will check the documentation of NullableTypes to see if
I stated something confusing about Nothing. If you will
have the opportunity to see the NullableTypes
documentation please let me know if you find something
confusing for VB.NET programmers.
Thanks, (luKa)

-----Original Message-----
Did you have something to say? As all I see is an empty trimmed message!
"Luca Minudel" <an*******@discussions.microsoft.com> wrote in messagenews:35****************************@phx.gbl...
>-----Original Message-----
>Luca,
>> Actually the .NET Framework don't let you set Null
>> (Nothing in VB) to an int, a bool, a DateTime, etc.
>However! VB.NET treats Nothing as the default value for

any type.
>
>Hope this helps
>Jay
>
>
>"Luca Minudel" <an*******@discussions.microsoft.com> wrote >>
>> If you need to set Null (Nothing in VB) to an int, a bool, >> a DateTime, ... you can use NullableTypes:
>> http://nullabletypes.sourceforge.net/
>>


Nov 20 '05 #13
Here it is! -

Yes this help! I'm primarely a C# programmer so I made
some confusion about Nothing in VB.

What I meant is that NullableTypes let you set Null to an
int, a bool, a DateTime and to quite any built-in .NET
type. But Null is not the default value and it is not
Nothing. It's a different value and it is strong typed
(i.e. Null for a DateTime is different from a Null for a
bool).

If you will have the opportunity to see the NullableTypes
documentation please let me know if you find something
confusing for VB.NET programmers.

Thanks, (luKa)

-----Original Message-----
Luca,
??

Did you have something to say? As all I see is an empty trimmed message!
Thanks
Jay

"Luca Minudel" <an*******@discussions.microsoft.com> wrote in messagenews:35****************************@phx.gbl...
>-----Original Message-----
>Luca,
>> Actually the .NET Framework don't let you set Null
>> (Nothing in VB) to an int, a bool, a DateTime, etc.
>However! VB.NET treats Nothing as the default value for

any type.
>
>Hope this helps
>Jay
>
>
>"Luca Minudel" <an*******@discussions.microsoft.com> wrote >>
>> If you need to set Null (Nothing in VB) to an int, a bool, >> a DateTime, ... you can use NullableTypes:
>> http://nullabletypes.sourceforge.net/
>>


Nov 20 '05 #14
Luca,
I follow you, your other post was just a little terse, I missed what you
were attempting to say.

NullableTypes allows the concept of a DB Null.

I was not talking about the concept of a DB Null, so I missed your
connection.

Thanks
Jay

"Luca Minudel" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Here it is! -

Yes this help! I'm primarely a C# programmer so I made
some confusion about Nothing in VB.

What I meant is that NullableTypes let you set Null to an
int, a bool, a DateTime and to quite any built-in .NET
type. But Null is not the default value and it is not
Nothing. It's a different value and it is strong typed
(i.e. Null for a DateTime is different from a Null for a
bool).

If you will have the opportunity to see the NullableTypes
documentation please let me know if you find something
confusing for VB.NET programmers.

Thanks, (luKa)

-----Original Message-----
Luca,
??

Did you have something to say? As all I see is an empty

trimmed message!

Thanks
Jay

"Luca Minudel" <an*******@discussions.microsoft.com>

wrote in message
news:35****************************@phx.gbl...

>-----Original Message-----
>Luca,
>> Actually the .NET Framework don't let you set Null
>> (Nothing in VB) to an int, a bool, a DateTime, etc.
>However! VB.NET treats Nothing as the default value for
any type.
>
>Hope this helps
>Jay
>
>
>"Luca Minudel" <an*******@discussions.microsoft.com> wrote >>
>> If you need to set Null (Nothing in VB) to an int, a bool, >> a DateTime, ... you can use NullableTypes:
>> http://nullabletypes.sourceforge.net/
>>

Nov 20 '05 #15
Yes this help. I'm primarely a C# programmers... I get
confuser about Nothing value VB.NET.

What I meant is that the Null value that NullableTypes let
you set to an int, a bool, a DateTime and to quite any .NET
built-in type is not the default value of that type (as
Nothing) but is a different value and is strong typed (a
Null int have a different type from a Null bool).

If you will have the opportunity to read the NullableTypes
documentation, please let me know if you find other
confusing statement for a VB.NET programmer.

ciao (luKa)
>-----Original Message-----
>Luca,
>> Actually the .NET Framework don't let you set Null
>> (Nothing in VB) to an int, a bool, a DateTime, etc.
>However! VB.NET treats Nothing as the default value for

any type.
>
>Hope this helps
>Jay
>
>
>"Luca Minudel" <an*******@discussions.microsoft.com> wrote
>>
>> If you need to set Null (Nothing in VB) to an int, a bool, >> a DateTime, ... you can use NullableTypes:
>> http://nullabletypes.sourceforge.net/
>>


Nov 20 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Doug Ly | last post by:
Hi, I use WinSQL to execute a query. It takes the sum of a column. Within the column, there are several NULL values and winSQL complains that it cannot add NULL values. Does anybody have an...
0
by: Benny Raymond | last post by:
reply to: benny@pocketrocks.com if possible: I'm trying to set up a hierarchy system in this database where each row can be related to a previous row. The problem is that when I go to...
4
by: Roy | last post by:
Hi all, How can I assign null to an integer. This doesn't work Dim intMyValue As Integer intMyVal = System.DBNull.Value Thanks in advance, Roy
8
by: Pablo S | last post by:
Hi all, I have search high and low on this - Take for instance the statement : insert into foo (text1, text2, int1) values ('Foo', 'Bar', ''); On Pg 7.2.x, the db would happily insert the...
26
by: Martin R | last post by:
Hi, How to find first not null value in column whitout chacking whole table (if there is a not null value then show me it and stop searching, the table is quite big)? thx, Martin *** Sent...
4
by: Learner | last post by:
Hello, I have database field called 'PullAHead' defined as a bit field. Now if user doesn't pick a 'Yes' or 'No' in the front I need to be able to send a null value into the 'PullAHead' field in...
12
by: Aidan | last post by:
I have a form to create a new record for a training course. The form is based on one table that has 4 keys set to primary key. The first combo box on the form allows selection of the course POP...
4
by: Greg (codepug | last post by:
Private Sub cboBody_KeyDown(KeyCode As Integer, SHIFT As Integer) 'Delete combobox entry if Del or Backspace key is hit. If (KeyCode = 46) Or (KeyCode = 8) Then Me.cboBody = "" End Sub I have...
5
by: bkberg05 | last post by:
Hi - I have a combo box field on a form. The field is required (can't be left blank). Occassionally a user will come to the field and the combo box will not contain the desired record. So I added...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.