SharePoint list CAML query using CONTAINS

夙愿已清 提交于 2019-12-10 01:08:33

问题


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();

回答1:


Leave out the surrounding Query tag, just use:

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

SPQuery adds the Query tag itself.



来源:https://stackoverflow.com/questions/1870314/sharepoint-list-caml-query-using-contains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!