0

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);

1 Answer 1

2

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.

2
  • 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, 2012 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. Jul 30, 2012 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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