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 / C# / August 2007

Tip: Looking for answers? Try searching our database.

Strange null value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RichB - 30 Aug 2007 10:02 GMT
I have a strange null value, which is displayed in the screen print here:

http://devscreens.blogspot.com/

If you look at the variables in the bottom half of the screen, third line
down is the value of key ["@sch_id], which clearly has a value, whilst in
the row 2 rows below cr.Keys["sch_id"] it is reported as null.

Keys is a hashtable (perhaps with a confusing name in hindsight) which
contains the parameters as the Key, and coresponding values from a stored
procedure.

This works elsewhere in my code with other id fields retrieved from the
database, but before I go providing a whole lot of classes, can somone
explain why there might be a difference betweeen these two rows?

Many Thanks,
Richard
Jon Skeet [C# MVP] - 30 Aug 2007 10:28 GMT
> I have a strange null value, which is displayed in the screen print here:
>
[quoted text clipped - 3 lines]
> down is the value of key ["@sch_id], which clearly has a value, whilst in
> the row 2 rows below cr.Keys["sch_id"] it is reported as null.

That's entirely reasonable. A hashtable can contain an entry with a
null value, and it looks like that's what's happening here.

For instance:

Hashtable x = new Hashtable();
x["key"] = null;

x.ContainsKey("key") will return true; x["key"] will return null.

Jon
RichB - 30 Aug 2007 10:36 GMT
Thanks, that is all understood, but I can't see it in this case.

In the secod row the cr.Keys["@sch_id"] contains the value
{35b92307-a090-4c27-9a66-a57b605eff92},
whilst in row 5 cr.Keys["@sch_id"] it is null.

I thought that these were both the same variable, if this is not the case,
then how to I access the {35b92307-a090-4c27-9a66-a57b605eff92}?

Thanks, Richard

>> I have a strange null value, which is displayed in the screen print here:
>>
[quoted text clipped - 15 lines]
>
> Jon
Jon Skeet [C# MVP] - 30 Aug 2007 10:47 GMT
> Thanks, that is all understood, but I can't see it in this case.
>
[quoted text clipped - 4 lines]
> I thought that these were both the same variable, if this is not the case,
> then how to I access the {35b92307-a090-4c27-9a66-a57b605eff92}?

Oops, yes I see now.

However, you need to look really carefully at the keys. You're asking
for "sch_id" but the only key in there is "@sch_id". Note the "@" at
the front. (Likewise row 5 shows cr.Keys["sch_id"].)

Jon
RichB - 30 Aug 2007 10:49 GMT
Thanks, good spot....I couldn't see it for looking!!

>> Thanks, that is all understood, but I can't see it in this case.
>>
[quoted text clipped - 13 lines]
>
> Jon
Jeffrey Tan[MSFT] - 31 Aug 2007 07:12 GMT
Hi Richard,

Is your problem resolved? Yes, while retrieving the Hashtable.Item property
using a key, we should use the same key for it(without missing the "@"
character). As stated in the "Property Value" section in the link below, if
the key you passed is not the previous one(not found), the Hashtable.Item
will return a null reference. This explains the behavior:
http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.item(V
S.71).aspx

Anyway, if you need further help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

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.