Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking for valid Guid in DataRow
Message
From
22/09/2008 14:25:44
 
 
To
22/09/2008 14:11:19
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01349517
Message ID:
01349577
Views:
19
>>>>>Hi all,
>>>>>
>>>>>I need to verify a DataRow has valid values and thus I am checking my PK which is a Guid.
>>>>>
>>>>>I am doing this:
>>>>>
>>>>>if ((Guid)dr["Track_Id"] != null || (Guid)dr["Track_Id"] != Guid.Empty)
>>>>>{
>>>>>
>>>>>}
>>>>>
>>>>>
>>>>>I am getting a message "Unreachable expression code detected" on the last portion of the check.
>>>>
>>>>Second expression would only be evaluated if (Guid)dr["Track_Id"] evaluated to null . I guess you intended &&......
>>>
>>>Oh, I see the point. I should turn those two around then. Thanks Viv
>>>
>>>
>>>if ((Guid)dr["Track_Id"] != Guid.Empty || (Guid)dr["Track_Id"] != null)
>>>
>>
>>Top of my head I don't think Guid is a nullable type so the second part is probably uneccessary anyway. Maybe:
>>
>>if (dr["Track_Id"] is Guid && (Guid)dr["Track_Id"] != Guid.Emptyl)
>>but that may be overkill ?
>
>Hmm, well I was thinking since the DataRow was derived from a serialized read it could get left null. Paul posted a suggestion for that.

I like mine better than Paul's (g) - it quarantees the second expression won't fail (i.e. the cast to Guid will work) ; Paul's checks that it's not null but NOT that it is indeed a Guid....

You were also right in your first post about && rather than || I just didn't catch it.
>Thanks
>Tim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform