Try our conversational search powered by Generative AI!

UserQuery - Filter on club-membership


I'm trying to get a list of all users who are members of some specified of clubs, but I keep getting a null-reference exception when I execute the query.

The code I'm using:
MembershipCriterion crit = newMembershipCriterion();
crit.Club = newClubCriterion();
crit.Club.ID = newIntegerCriterion();
crit.Club.ID.Includes = newIntegerInCriterion();
foreach (ListItem item in clubs.Items.OfType<ListItem>().Where( t => t.Selected ).ToList())
    crit.Club.ID.Includes.Values.Add( Convert.ToInt32( item.Value ) );
query.Criteria.Add( "Clubs", crit );

Any idea what could be wrong with this code?


Jun 06, 2011 16:54

Well, you're not checking null references in your code... I have done some similar stuff (but the code is buried deep), but look at this post by Karoline

Maybe that can give you some help

Jun 10, 2011 15:31

Since the clubs are retrieved from a dropdownlist, which is previously filled from a club-query, I see no points where a null-reference could occur. Where should I check for null-recerences then?

Jun 14, 2011 16:17

crit.Club.ID.Includes.Values.Add( Convert.ToInt32( item.Value ) ); - item.Value, I think Convert will fail if there is no data in item.Value. Haven't tested the code, but it could happen, maybe =)

Jun 14, 2011 16:44

But item.Value has  a value. The error also occurs on the execution of the query, not on converting the value of the item.

Jun 15, 2011 9:19
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.