SharePoint:如何使用CAML查询检查null?

JL.*_*JL. 25 sharepoint

我有这个CAML:

query.Query = @"<Where><Eq><FieldRef Name='MessageID' /><Value Type='Text'></Value></Eq></Where>";
Run Code Online (Sandbox Code Playgroud)

这将检查MessageID = string.empty()的值

我想检查的是null ....不是空字符串...

这可能与CAML有关吗?

Col*_*lin 52

CAML有IsNull运算符,因此查询将是:

query.Query = @"<Where><IsNull><FieldRef Name='MessageID' /></IsNull></Where>"
Run Code Online (Sandbox Code Playgroud)

  • 凉!PS我怎么知道这些东西?主要通过许多沮丧的时间:-D (4认同)

小智 25

需要相当于String.IsNullOrEmpty(Description).结束了这个:

<And>
  <IsNotNull>  
    <FieldRef Name='Description' />   
  </IsNotNull>  
  <Neq>  
    <FieldRef Name='Description' />  
    <Value Type='Text'></Value>  
  </Neq>
</And>
Run Code Online (Sandbox Code Playgroud)

  • 请注意,在复制和粘贴之前,它已被否定了IsNullOrEmpty;) (5认同)

Dou*_*las 12

同意Colin,更常用的条件如下:

1. Null:
<Where><IsNull><FieldRef Name="CustomField" /></IsNull></Where>
2. Not Null:
<Where><IsNotNull><FieldRef Name="CustomField" /></IsNotNull></Where>
3. Equal:
<Where><Eq><FieldRef Name="CustomField" /><Value Type="Text">MatchValue</Value></Eq></Where>
4. Not Equal?
<Where><Neq><FieldRef Name="CustomField" /><Value Type="Text">MatchValue</Value></Neq></Where>
5. Greater Than?
<Where><Gt><FieldRef Name="CustomField" /><Value Type="Text">1</Value></Gt></Where>
6. Greater Than And Equal?
<Where><Geq><FieldRef Name="CustomField" /><Value Type="Text">1</Value></Geq></Where>
7. Lower Than:
<Where><Lt><FieldRef Name="CustomField" /><Value Type="Text">1</Value></Lt></Where>
8. Lower Than And Equal:
<Where><Leq><FieldRef Name="CustomField" /><Value Type="Text">1</Value></Leq></Where>
9 Begin With:
<Where><BeginsWith><FieldRef Name="CustomField" /><Value Type="Text">StartString</Value></BeginsWith></Where>
10: Contains:
<Where><Contains><FieldRef Name="CustomField" /><Value Type="Text">ContainString</Value></Contains></Where>
Run Code Online (Sandbox Code Playgroud)

注意:更多信息请访问:http://msdn.microsoft.com/en-us/library/ms467521.aspx 有完全Caml查询架构.

希望这可以帮到你〜