Search code examples
sharepointsharepoint-2007caml

CAML query returns wrong results?


I have the following code:

                    SPQuery oQuery = new SPQuery();
                    oQuery.Query = @"<Query>
                                           <Where>
                                              <And>
                                                 <Eq>
                                                    <FieldRef Name='PublishToSM' />
                                                    <Value Type='Boolean'>1</Value>
                                                 </Eq>
                                                 <IsNull>
                                                    <FieldRef Name='SMUpdateDate' />
                                                 </IsNull>
                                              </And>
                                           </Where>
                                        </Query>";
                    SPListItemCollection collListItems = list.GetItems(oQuery);

                    NevCoSocialMedia.NevCoFacebook fb = new NevCoSocialMedia.NevCoFacebook();

                    foreach (SPListItem oListItem in collListItems)
                    {
                        if (oListItem.Fields.ContainsField("PublishToSM") && Convert.ToBoolean(oListItem["PublishToSM"]) == true)
                        {
.
.
.

My question is why do I need to have the last if statement? If I don't have this it will throw an error saying that the identifier does not exist when it tries to do oListItem["PublishToSM"]. This seems impossible since my CAML query is checking that that has an appropriate value...


Solution

  • remove the "query" element

    wrapping your caml