使用 CONTAINS 的 SharePoint 列表 CAML 查询 [英] SharePoint list CAML query using CONTAINS

查看:91
本文介绍了使用 CONTAINS 的 SharePoint 列表 CAML 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 webpart 中使用以下 CAML 查询来查询 SharePoint 列表.我已经在 U2U CAML Query Builder 和 Stramit CAML Viewer 中测试了查询,它工作正常,只返回匹配的记录,但是当我在我的 webpart 中使用它时,它返回所有列表项.它让我疯狂.代码如下:

I'm trying to query a SharePoint list using the following CAML query in a webpart. I have tested the query in U2U CAML Query Builder and Stramit CAML Viewer and it works fine, only returning the matching records, but when I use it in my webpart it return all list items. It is driving me crazyyyyy. Here is the code:

string camlQuery = string.Format(@"<Query><Where><Contains><FieldRef Name='Title' /><Value Type='Text'>2</Value></Contains></Where></Query>");

SPQuery query = new SPQuery();
query.Query = camlQuery;
SPListItemCollection items = Articles.GetItems(query);
grid.DataSource = items.GetDataTable();
grid.DataBind();

推荐答案

去掉周围的Query标签,直接使用:

Leave out the surrounding Query tag, just use:

<Where><Contains><FieldRef Name='Title' /><Value Type='Text'>2</Value></Contains></Where>

SPQuery 添加查询标签本身.

SPQuery adds the Query tag itself.

这篇关于使用 CONTAINS 的 SharePoint 列表 CAML 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆