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?
rneemanPosted Nov 4, 2003, 6:44 AM
bonniebPosted Oct 14, 2003, 8:35 PM
thed0ct0rPosted Oct 14, 2003, 6:12 AM
johnsolomonPosted Oct 11, 2003, 12:47 PM
AdministratorPosted Mar 31, 2003, 5:46 AM