Solved

CAML Query with Contains not working

Posted on 2011-03-20
4
663 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 5

Expert Comment

by:navdeepmadan
Comment Utility
0
 
LVL 14

Accepted Solution

by:
KoenVosters earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
gl at m* ;-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When installing SharePoint 2010 RTM I came across a strange error, I was getting timeouts during the installation. I searched the web and found the best solution to be found here (http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010genera…
For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now