PC Review


Reply
Thread Tools Rate Thread

How to check if value is 'null'

 
 
GS
Guest
Posts: n/a
 
      15th Jan 2006
Hi,

I have following value which I need to check wether it's null or not. Issue is that StartPrice itself can be a null and checking (myItem.StartPrice.Value == null) do not produce true.
How do I check for null in this kind of case. I don't want to check StartPrice for null and then Value for null again as one option. I just want to check Value for null.
Thanks,
Greg

 
Reply With Quote
 
 
 
 
Brian Lin
Guest
Posts: n/a
 
      15th Jan 2006
GS wrote:
> Hi,
>
> I have following value which I need to check wether it's null or not.
> Issue is that StartPrice itself can be a null and checking
> (myItem.StartPrice.Value == null) do not produce true.
> How do I check for null in this kind of case. I don't want to check
> StartPrice for null and then Value for null again as one option. I just
> want to check Value for null.
>
> Thanks,
> Greg
>

myItem.StartPrice.Value IS Nothing ?
 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      15th Jan 2006
Does not work since myItem.StartPrice is null (Nothing in VB) itself and
hence I can not check myItem.StartPrice.Value

"Brian Lin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> GS wrote:
>> Hi,
>> I have following value which I need to check wether it's null or not.
>> Issue is that StartPrice itself can be a null and checking
>> (myItem.StartPrice.Value == null) do not produce true.
>> How do I check for null in this kind of case. I don't want to check
>> StartPrice for null and then Value for null again as one option. I just
>> want to check Value for null.
>>
>> Thanks,
>> Greg
>>

> myItem.StartPrice.Value IS Nothing ?



 
Reply With Quote
 
Luke Dalessandro
Guest
Posts: n/a
 
      15th Jan 2006
GS wrote:
> Hi,
>
> I have following value which I need to check wether it's null or not.
> Issue is that StartPrice itself can be a null and checking
> (myItem.StartPrice.Value == null) do not produce true.
> How do I check for null in this kind of case. I don't want to check
> StartPrice for null and then Value for null again as one option. I just
> want to check Value for null.
>
> Thanks,
> Greg
>

Just do this:

if ((null == myItem.StartPrice) || (null == myItem.StartPrice.Value))
{
// Either .StartPrice or .Value is null, handle that here
}
else
{
// Do stuff with .Value
}

The second test is never evaluated if the first test is true (it's
"short-circuited"), so you won't get an exception. Keep in mind that you
might need to use a different test on the .Value check if .Value is an
int or a string.

Hope this helps,
Luke
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if date field not null or >0 check check box JK Microsoft Access VBA Modules 4 28th Jan 2009 03:44 PM
Check null RP Microsoft C# .NET 4 12th Nov 2007 04:58 PM
Check if it is null shapper Microsoft ASP .NET 1 11th Oct 2006 08:11 PM
Check for Null =?Utf-8?B?S2lyayBQLg==?= Microsoft Access Form Coding 5 25th Jul 2006 06:57 PM
How to check for null tshad Microsoft C# .NET 12 6th Oct 2005 01:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:33 AM.