Discussion:
ConditionOperator.In with multiple values
(too old to reply)
Purple
2006-07-18 14:18:01 UTC
Permalink
Why doesn't this work?

The value 3;8 is passed to my class as a string.
I convert this string to "3","8"

...

_s_status = "\"" + Replace(_s_status, ";", "\",\"") + "\"";

...

string[] customertypecode = new string[] { s_status };
ConditionExpression StatusIn = new ConditionExpression();
StatusIn.AttributeName = "customertypecode";
StatusIn.Operator = ConditionOperator.In;
StatusIn.Values = customertypecode;

ConditionExpression likeName = new ConditionExpression();
likeName.AttributeName = "name";
likeName.Operator = ConditionOperator.Like;
likeName.Values = new object[] { s_name + "%" };

...

FilterExpression filter = new FilterExpression();
filter.Conditions = new ConditionExpression[] { likeName, likeZipcode,
likeTown, StatusIn };
filter.FilterOperator = LogicalOperator.And;

query.Criteria = filter;

BusinessEntityCollection returnedaccounts = s.RetrieveMultiple(query);







BUT it works when I type
string[] customertypecode = new string[] { "3,"8" };




What is the difference?
Michael Höhne
2006-07-18 15:22:14 UTC
Permalink
The difference is that your first approach will build a query like

SELECT * FROM Entity WHERE (customertypecode IN ('"3,8"')) AND ...

The second (correct) code produces the following statement:

SELECT * FROM Entity WHERE (customertypecode IN (3, 8)) AND ...


Multiple parameters are allways passed as an array, which is the reason why
the Values property is an array and not a single object.
--
Michael

http://www.stunnware.com/crm2

----------------------------------------------------------
Post by Purple
Why doesn't this work?
The value 3;8 is passed to my class as a string.
I convert this string to "3","8"
...
_s_status = "\"" + Replace(_s_status, ";", "\",\"") + "\"";
...
string[] customertypecode = new string[] { s_status };
ConditionExpression StatusIn = new ConditionExpression();
StatusIn.AttributeName = "customertypecode";
StatusIn.Operator = ConditionOperator.In;
StatusIn.Values = customertypecode;
ConditionExpression likeName = new ConditionExpression();
likeName.AttributeName = "name";
likeName.Operator = ConditionOperator.Like;
likeName.Values = new object[] { s_name + "%" };
...
FilterExpression filter = new FilterExpression();
filter.Conditions = new ConditionExpression[] { likeName, likeZipcode,
likeTown, StatusIn };
filter.FilterOperator = LogicalOperator.And;
query.Criteria = filter;
BusinessEntityCollection returnedaccounts = s.RetrieveMultiple(query);
BUT it works when I type
string[] customertypecode = new string[] { "3,"8" };
What is the difference?
Purple
2006-07-18 16:47:02 UTC
Permalink
Thanx!
Post by Michael Höhne
The difference is that your first approach will build a query like
SELECT * FROM Entity WHERE (customertypecode IN ('"3,8"')) AND ...
SELECT * FROM Entity WHERE (customertypecode IN (3, 8)) AND ...
Multiple parameters are allways passed as an array, which is the reason why
the Values property is an array and not a single object.
--
Michael
http://www.stunnware.com/crm2
----------------------------------------------------------
Post by Purple
Why doesn't this work?
The value 3;8 is passed to my class as a string.
I convert this string to "3","8"
...
_s_status = "\"" + Replace(_s_status, ";", "\",\"") + "\"";
...
string[] customertypecode = new string[] { s_status };
ConditionExpression StatusIn = new ConditionExpression();
StatusIn.AttributeName = "customertypecode";
StatusIn.Operator = ConditionOperator.In;
StatusIn.Values = customertypecode;
ConditionExpression likeName = new ConditionExpression();
likeName.AttributeName = "name";
likeName.Operator = ConditionOperator.Like;
likeName.Values = new object[] { s_name + "%" };
...
FilterExpression filter = new FilterExpression();
filter.Conditions = new ConditionExpression[] { likeName, likeZipcode,
likeTown, StatusIn };
filter.FilterOperator = LogicalOperator.And;
query.Criteria = filter;
BusinessEntityCollection returnedaccounts = s.RetrieveMultiple(query);
BUT it works when I type
string[] customertypecode = new string[] { "3,"8" };
What is the difference?
Loading...