Handling null values
Hi all!
This is maybe a design question but anyway, I've got a prb.
I have written a class (let's say USER). The data is stored in table myuser that has fields
int UserId, varchar UserName and int GroupID
The User class has of course these same fields. I also have a data acces component that should return me a User object. But the problem is, that GroupID may be null (that is, user doesn't belong to any group)
How should I handle that? Ok, DataReaders have IsDbNull property and I can use it to avoid problems when reading data. But how about when I have read the data, instantiated a User object and passed it to another layer, I need to check whether the user belongs to a group.
Now the big problem.
If I try
if (MyUser.Group != null)
DoSomething(MyUser.ID, MyUser.Group);
I get an error "Operator '!=' cannot be applied to operands of type 'int' and ''"
How to do this?

AdministratorRank #675 · 3.6K reputationPosted Mar 31, 2003, 12:46 AM EST
johnsolomon4 reputationPosted Oct 11, 2003, 8:47 AM EDT
thed0ct0r84 reputationPosted Oct 14, 2003, 2:12 AM EDT
bonnieb48 reputationPosted Oct 14, 2003, 4:35 PM EDT
rneeman4 reputationPosted Nov 4, 2003, 1:44 AM EST