If (user == null) statement

Posts   
 
    
mmeenagh31 avatar
mmeenagh31
User
Posts: 3
Joined: 30-Jun-2005
# Posted on: 11-Jul-2005 07:01:56   

I'm trying to check if a user is in table and if not post an error message

This is the code but if user is not in table it still says recognized when it should say unknown

   UserCollection user = new UserCollection();
        IPredicateExpression selectFilter = new PredicateExpression();
        selectFilter.Add(PredicateFactory.CompareValue(UserFieldIndex.Email, ComparisonOperator.Equal, __LoginField.Text));
        user.GetMulti(selectFilter);
        if (user == null)
      {
        __Msg.Text = "Unknown email address \"" + __LoginField.Text + "\".";
      }
else 
{
        __Msg.Text = "Recognized email address \"" + __LoginField.Text + "\".";
      }

       else
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Jul-2005 08:08:39   

user is never null, as you instantiate it to an instance: UserCollection user = new UserCollection();

Test on user.Count being > 0 or 0

You can also use GetScalar to find out if an entity is in the db.

Frans Bouma | Lead developer LLBLGen Pro