Strange null value

  • Thread starter Thread starter RichB
  • Start date Start date
R

RichB

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
 
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.

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
 
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



Jon Skeet said:
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.

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
 
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}?

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
 
Thanks, good spot....I couldn't see it for looking!!

Jon Skeet said:
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}?

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
 
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.
 
Back
Top