Executing SPQuery Queries and the U2U CAML Query Builder
July 7, 2009 2 Comments
If you are querying against any list using the SPQuery method, then most likely you are using the U2U CAML Query Builder. And if you are not, why? (This is old news! It’s been around since SharePoint 2003) This utility is always one of the first installations to any of my development environments.
This utility makes your life much easier by allowing you to build and test your queries directly against SharePoint, before debugging them, through code. And you can also do it remotely via web services, so you do not have to install and run this directly from the server itself.
A newer version was released last year as well that will install directly into your farm via a feature, to allow you to build, test, and save queries all from the SharePoint UI!
However, a common issue takes place when you copy the query directly from the U2U CAML Query Builder (which works just fine in the utility itself), in that no matter what conditions you have specified for your query, you always retrieve all list items. If this is the first time you have run into this – you have no doubt done a little of the timeless developer troubleshooting method
- Bang head against desk
- Repeat
You need not worry however, this is a quick fix. The U2U CAML Query Builder inserts <Query> </Query> tags around the query itself. In your code, just drop these start and end tags from your query, and you should now be returning your expected results.
Nice !!!!!!!!SpQuery and CAML in Sharepoint, it is simple.Try this too,http://sarangasl.blogspot.com/2009/10/caml-spquery-in-sharepoint.html
I find the answer is
I change the query like
query.Query = string.Concat(“”, “”, “” + competencyAssessedUnit + “”, “”); SPListItemCollection items = list.GetItems(query);
Just replace string to Text