Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Handling null values

Mar 31 2003 5:37 AM
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?

Answers (5)