locked
"eq" operator has some invalid Operand Error RRS feed

  • Question

  • Hi Experts, What is wrong with the below code that it is throwing exception that the operator eq has some invalid operand.

    Please give some solution.

    Thank you.

      private void GetContactId(string roleTypeId)
            { 
                
               
             string criteriaOrder = "AccountRoleCode eq ('" + roleTypeId + "') ";
                DataServiceQuery<Contact> query = (DataServiceQuery<Contact>)_crmODataContext.ContactSet;
                query = query.AddQueryOption("$filter", criteriaOrder);
                query.BeginExecute(ContactResult, query);
            }


    saroj

    Friday, August 10, 2012 7:17 AM

Answers

  • Hi Saroj,

    You should use:

     private void GetContactId(string roleTypeId)
            { 
                
               
             string criteriaOrder = "AccountRoleCode/Value eq (" + roleTypeId + ") ";
                DataServiceQuery<Contact> query = (DataServiceQuery<Contact>)_crmODataContext.ContactSet;
                query = query.AddQueryOption("$filter", criteriaOrder);
                query.BeginExecute(ContactResult, query);
            }

    ie. Add the /Value and remove the single quotes (')

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, August 10, 2012 7:34 AM
    Answerer

All replies

  • Hi Saroj,

    You should use:

     private void GetContactId(string roleTypeId)
            { 
                
               
             string criteriaOrder = "AccountRoleCode/Value eq (" + roleTypeId + ") ";
                DataServiceQuery<Contact> query = (DataServiceQuery<Contact>)_crmODataContext.ContactSet;
                query = query.AddQueryOption("$filter", criteriaOrder);
                query.BeginExecute(ContactResult, query);
            }

    ie. Add the /Value and remove the single quotes (')

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, August 10, 2012 7:34 AM
    Answerer
  • Try this:

    string criteriaOrder = "AccountRoleCode/Value eq " + roleTypeId + " ";

    This should be the correct format for optionsets.

    /Jonas

    Jonas Rapp's CRM Trenches 

    Friday, August 10, 2012 7:36 AM
  • Thank you very much Scott. Your suggestion worked.

    saroj

    Friday, August 10, 2012 8:52 AM