C# 布尔列的 CAML 查询不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11219772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:01:59  来源:igfitidea点击:

CAML query for boolean column is not working

c#sharepointcaml

提问by Nirushan Ferdinand Chandran

Hi I have a SharePoint list to be queried for my Desktop App and I want to retrieve only the Active Members but when I queried I got only the users who aren't active. What is wrong with my CAML query?

您好,我有一个 SharePoint 列表要查询我的桌面应用程序,我只想检索活动成员,但是当我查询时,我只得到了非活动用户。我的 CAML 查询有什么问题?

camlQuery.ViewXml = "<<"View">><Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> " + true + "</Value></Eq></Where></Query></View>"";

I tried the following as well

我也尝试了以下

camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> true</Value></Eq></Where></Query></View>";

and

camlQuery.ViewXml = "<Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> true</Value></Eq></Where></Query>";

Please help as I'm new to CAML.

请帮助,因为我是 CAML 的新手。

采纳答案by Ryan

Save yourself some grief and use a tool to help build up CAML queries such as U2U's Caml Query Builder.

省去一些麻烦并使用工具来帮助构建 CAML 查询,例如U2U 的 Caml Query Builder。

You need to use 1 and 0 (not true and false) in the query, so

您需要在查询中使用 1 和 0(不是真假),所以

<Query><Where>
   <Eq><FieldRef Name="Active" /><Value Type="Boolean">1</Value></Eq>
</Where></Query>

回答by user2470731

Use the value type Booland it works with "true", "True" or "TRUE"

使用值类型Bool,它适用于“true”、“True”或“TRUE”

回答by DevTard

This Works for me

这对我有用

camlQuery.ViewXml = "<View>" + "<Query>" + "<Where>" + "<Eq>" +
"<FieldRef Name='Active'/>" + " <Value Type='Boolean'>" + "1" + "</Value>" +
"</Eq>" + "</Where>" + "</Query>" + "</View>";