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 am trying to query a custom list and getting the following error:

enter image description here

At,

SPListItemCollection OsplistitemCollection = Olist.GetItems(OqueryResponse);

below is my code

string TicketID = "123";
Osite = new SPSite(noPrevSite.ID);
Oweb = Osite.OpenWeb(noPrevWeb.ID);
Olist = Oweb.Lists["ListName"];

helpDeskIDLabel.Text = TicketID;
camlQuery = "<Where><Contains><FieldRef Name='TicketID'/<Value Type='Text'>" 
                      + TicketID+ "</Value></Contains></Where>";
OqueryResponse.Query = camlQuery; 
SPListItemCollection OsplistitemCollection = Olist.GetItems(OqueryResponse);
string count = OsplistitemCollection.Count.ToString();

Update -->ULS Log

Unable to execute query: Error 0x81020014 One or more field types are not installed properly. Go to the list settings page to delete these fields.

share|improve this question
1  
Please verify that this is code you are using because even after I applied some formating it looks... confusing. Btw one > is missing after TicketID in query string (?) –  Vedran Rasol Feb 8 '12 at 20:15
    
yes it was wil copy pasting it that i miss the > –  spStacker Feb 9 '12 at 17:13

2 Answers 2

up vote 3 down vote accepted

You get that error when the fields used in CAML query fields or viewfields are not present in that list. CAML uses the internal name and not the display name. Verify that the ticketid is the internal name of that field and not display name. Go to list settings and click on the field ticketid and observe the url for the param value 'field'. This should match the one used in CAML. It is very likely that someone changed the column's display name after it was created, so the display name would be different from the internal name.

share|improve this answer
    
I would bet this is the likely cause of the problem. I cannot count the number of times I have changed the Title field's display name and then forgotten that I did this afterwards. –  Robert Kaucher Mar 13 '12 at 0:39
    
yeah right check your fields properly –  naijacoder Mar 13 '12 at 7:30

If TicketID is text field and your goal is to get all tickets containing some value then code (written from head!) is:

string TicketId = "123";
using(SPSite oSite = new SPSite(noPrevSite.ID)
{
    using(SPWeb oWeb = oSite.OpenWeb(noPrevWeb.ID))
    {
         SPList oList = oWeb.Lists["ListName"];
         SPQuery query = new SPQuery();
         query.Query = "<Where><Contains><FieldRef Name='TicketID'/><Value Type='Text'>" 
                  + TicketId + "</Value></Contains></Where>";
         SPListItemCollection oSplistitemCollection = oList.GetItems(query);
         string count = oSplistitemCollection.Count.ToString();
    }
}

Also it is not a bad idea to check your list and verify that TicketID is present. However there are other reasons for this query to fail but you need to provide more info and recheck that code you provided is really one you are using (see my comment).

share|improve this answer
    
hi vedran, i did check the ticketid,it is present in the list ..the custom list that i m using here is actually a custom list template from the production..and we did lotus notes migration on that list...does that might have caused the problem?..thanks –  spStacker Feb 9 '12 at 17:15

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.