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’/>” +
And the CAMLQuery like this
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = “<View><Query><Where><Geq><FieldRef Name=’Field2’/>” +
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
Hope this helps