This had me puzzled for a while, so let me spare you the agony.
I was writing code that queried a list using the GetListItems function of the SPList object. The query I was using was from the U2U Caml Creator (great application, even with the bugs) and was working on that application perfectly - filtering my list to return only the items I wanted.
But in my web part the query would return all items in the list, ignoring the filter I set.
After some tests I found the problem. Apperantly the SPQuery object automatically wraps your query with the "<query>" tag, and since the U2U Caml Creator application also generates queries with the "<query>" tag, you actually have two "<query>" tags in your query, which makes sharepoint ignore the filters you set in the query.
So next time you are using the SPQuery object, remember the Query property should receive a CAML query, but without the "<query>" tag. Only whats under it.
5 comments:
Hehe, I know this one too ;-)
I also blogged it: http://moldenco.blogspot.com/2006/11/using-caml-to-filter-infopath-published.html
Thanks for this. You will not believe how much time I spent trying to figure out why my CAML query with Query tags on both ends with a SPQuery object did not work.
thanks so much! i can go home now.
Thank You very Much!!! I was going crazy with CAML working in the tools and not with my Web Part.
"What A Query..."
thanks buddy.
Post a Comment