SharePoint: CAML query error when creating SPQuery query
I have this CAML query
var query = new SPQuery
{
Query = string.Format(@"<Where>
<Or>
<Or>
<Or>
<Or>
<Contains>
<FieldRef Name='{7}' />
<Value Type='Text'>{3}</Value>
</Contains>
</Or>
<Contains>
<FieldRef Name='{6}' />
<Value Type='Text'>{2}</Value>
</Contains>
</Or
<Contains>
开发者_JAVA技巧 <FieldRef Name='{5}' />
<Value Type='Text'>{1}</Value>
</Contains>
</Or>
<Contains>
<FieldRef Name='{4}' />
<Value Type='Text'>{0}</Value>
</Contains>
</Or>
</Where>", "title", "adress", "zipcode", "city", "searchTitle", "searchAdress", "searchZipcode", "searchCity")
};
Every time it's ran and I try to use List.GetItems(query);
it throws this error:
One or more field types are not installed properly. Go to the list settings page to delete these fields.
BUT! If I remove all the <Or>
tags it works and doesn't throw that error, but I need the <Or>
tags to make sure it get all hits.
I've made sure all the fieldrefs matches the internal names of the columns 100%.
Have you tried your query without the around the Contains 7/3 element? This one is imo not needed.
Also one of your /Or's has no closing bracket <Value Type='Text'>{2}</Value></Contains></Or<Contains>
, this could be causing the error.
correct your CAML
var query = new SPQuery
{
Query = string.Format(@"<Where>
<Or>
<Or>
<Or>
<Contains>
<FieldRef Name='{7}' />
<Value Type='Text'>{3}</Value>
</Contains>
<Contains>
<FieldRef Name='{6}' />
<Value Type='Text'>{2}</Value>
</Contains>
</Or>
<Contains>
<FieldRef Name='{5}' />
<Value Type='Text'>{1}</Value>
</Contains>
</Or>
<Contains>
<FieldRef Name='{4}' />
<Value Type='Text'>{0}</Value>
</Contains>
</Or>
</Where>", "title", "adress", "zipcode", "city", "searchTitle", "searchAdress", "searchZipcode", "searchCity")
};
精彩评论