U2U - CAML Query Builder
Wednesday, February 11th, 2009A time ago I need to write a SPQuery to query a List. I tested my query with the CAML Query Builder by Karine Bosch - U2U. After testing it I put the following query into my code like this:
SPList list = GetMyList();
SPQuery query = new SPQuery();
query.Query = “<Query><Where><Eq><FieldRef Name=’Title’/><Value Type=’Text’>TEST</Value></Eq></Where></Query>”;
list.GetItems(query);
The code above always return all items in the list. So I start looking at the query, after a few minutes I saw that I had set the Query property of the SPQuery object, so I had to remove <Query> and </Query> from my query. Like this:
query.Query = “<Where><Eq><FieldRef Name=’Title’/><Value Type=’Text’>TEST</Value></Eq></Where>”;
Otherwise the query is ignored and therefore all items from the list are returned.