Testing for a Null Value
![]() |
[Applies to: Microsoft Dynamics CRM 4.0]
The following code example show how to test for a null value by using the QueryExpression and QueryByAttribute classes.
Example
Use this code to test for equality by using the QueryExpression class:
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "leadid";
condition.Operator = ConditionOperator.Null;
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] { condition };
Example
Use this code to test for inequality by using the QueryExpression class:
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "leadid";
condition.Operator = ConditionOperator.NotNull;
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] { condition };
Example
Use this code to test for equality by using the QueryByAttribute class:
// Create a column set holding the names of the columns to be retrieved.
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {"name", "accountid"};
QueryByAttribute qba = new QueryByAttribute();
qba.EntityName = "account";
qba.ColumnSet = cols;
qba.Attributes = new string[]{"donotfax"};
qba.Values = new object[]{null};
See Also
Other Resources
© 2010 Microsoft Corporation. All rights reserved.

