SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a query I created using U2U CAML query. I am able to retrieve all the information within the builder, but when I use in VS I am returning everything seems like. Unless while debugging I am checking the wrong things. Need to verify that it is correct and should work in VS.

BTW, I checked the forum so it seems correct, may just need another set of eyes sometimes....code running together

                using (SPSite siteCol2 = new SPSite(""))
                    using (SPWeb web2 = siteCol2.OpenWeb())

                        SPList groupList = web2.Lists["Approvers"];

                        //Write SPQuery/CAML query
                        SPQuery myquery = new SPQuery();
                        myquery.Query =
                            //"<Query>" +
                            "<Where>" +
                            "<And>" +
                                    "<Contains>" +
                                        "<FieldRef Name='Group' />" + "<Value Type='Text'>PO</Value>" +
                                    "</Contains>" +
                            "</And>" +

                        SPListItemCollection items = groupList.GetItems(myquery);
share|improve this question
up vote 2 down vote accepted

You could rewrite it as such:

myquery.Query =
    "<Where>" +
        "<Contains>" +
            "<FieldRef Name='Group' />" +
            "<Value Type='Text'>PO</Value>" +
        "</Contains>" +

Your <And> clause only had 1 argument to evaluate.

(list["Group"].Value == "PO" && ) is effectively what your query says.

share|improve this answer
Oh okay, thanks....see, I needed another pair of eyes. I initally had two arguments, but was trying to use avariable in my query – nholloway4 Jul 30 '12 at 15:34
No problem. I totally understand. I feel sometimes even just trying to explain your problem to someone else causes your "Eureka!" moment. – RJ Cuthbertson Jul 30 '12 at 15:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.