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>
开发者_StackOverflow社区 <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...
remove the "query" element
wrapping your caml
Try changing the value type to an integer
<Eq>
<FieldRef Name='PublishToSM' />
<Value Type='Integer'>1</Value>
</Eq>
http://www.sharepointblues.com/2010/02/22/caml-and-querying-boolean-fields/
Always add ViewFields, if you don't, only basic fields like ID and Title get filled in the returned listitems.
I've encountered a weird problem with using the Boolean type in a caml query before as well. In 6 out of our 7 environments Boolean worked fine, but in one of them it did not and it totally messed up one of our workflows. We were never able to figure out why.
Try Integer or Bit for the 'PublishToSM' field and see if you get a different result.
精彩评论