Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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("http://dev.portal.net/it/dev"))
                {
                    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>" +
                            "</Where>";
                            //"</Query>";

                        SPListItemCollection items = groupList.GetItems(myquery);
                        Console.WriteLine(myquery);
share|improve this question

1 Answer 1

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>" +
    "</Where>";

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

 
discard

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.