Today I’ll talk about a mistake I’ve seen several times in the forums, namely the formatting of CAML queries.
When you want to use CAML queries, the two objects that are most often used are SPQuery and CamlQuery.
The SPQuery is used like this
SPQuery oQuery = new SPQuery();
oQuery.Query = “<Where><Geq><FieldRef Name=’Field2’/>” +
“<Value Type=’Number’>1000</Value></Geq></Where>”;
And the CAMLQuery like this
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = “<View><Query><Where><Geq><FieldRef Name=’Field2’/>” +
“<Value Type=’Number’>1000</Value></Geq></Where></Query></View>”;
Seeing the two uses you probably already saw the difference, but for those who have not been paying attention, look carefully to the contents of the query.
With SPQuery, the query starts and ends with the « Where » tags while with CAMLQuery, you have « View » and « Query » tags in extra !
It may sound easy but if you normally use an object and then the other, you can easily put any doubt except formatting the query.
More information on these two objects
SPQuery : http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.query.aspx
CAMLQuery : http://msdn.microsoft.com/en-us/library/ee534956(v=office.14).aspx
Hope this helps
Christopher.