Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CAML Query with Contains not working

Posted on 2011-03-20
4
Medium Priority
?
756 Views
Last Modified: 2012-05-11
I have a list called wraps with 12 items, no matter what I search using the following query, it always returns me the 12 items, so its not working correctly.

I debugged and the variable tag is OK.

  SPSite site = SPContext.Current.Site;
                // get the list
                SPList lstTagList = site.RootWeb.Lists.TryGetList("Wraps");
                if (lstTagList != null)
                {
                    // Try to find the item I want
                    SPQuery query = new SPQuery();
                    query.Query = "<Query><Where><Contains><FieldRef Name='Agenda_x0020_Tags' /><Value Type='Text'>" + tag + "</Value></Contains></Where></Query>";
                    SPListItemCollection foundItems = lstTagList.GetItems(query);
                    DataView dv = new DataView(foundItems.GetDataTable());
                    PagedDataSource page = new PagedDataSource();
                    page.AllowCustomPaging = true;
                    page.AllowPaging = true;
                    page.DataSource = dv;
                    page.PageSize = 10;
                   
                    WrapsRepeater.DataSource = page;
                    WrapsRepeater.DataBind();
0
Comment
Question by:LuisEstebanValencia
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
KoenVosters earned 2000 total points
ID: 35178417
navdeep maybe read the question?

Luis you are probably using the querybuilder of U2U. You need to remove the <query> tags from your query.
0
 

Author Closing Comment

by:LuisEstebanValencia
ID: 35179102
Navdeep didnt event read the question. He think that just pasting an url would give him the points, you did the homework.

Thank you
0
 
LVL 14

Expert Comment

by:KoenVosters
ID: 35179112
gl at m* ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question