5

I'm trying to query an SPList object using a CAML query (see code below).

SPQuery queryGetExistingTargetTask = new SPQuery();
queryGetExistingTargetTask.Query = string.Format(@"<Where><Eq><FieldRef Name=""TaskID""></FieldRef><Value Type=""Text"">{0}/Value></Eq></Where>", System.Security.SecurityElement.Escape(Convert.ToString(sourceTask["TaskID"])));
SPListItemCollection matchedTargetTasks = destinationList.GetItems(queryGetExistingTargetTask);

if (matchedTargetTasks.Count == 1) {...}

The SPList.GetITems call isn't throwing an error and it does return a SPListItemCollection Object. However, when I try to access any of the properties on the collection they throw an unhelpful error (see image below).

enter image description here

I'm fairly new to SharePoint development, so there is a good chance I am doing something very wrong here. Can you guys see anything obviously wrong with this code?

What I've tried so far:
- I confirmed that the destinationList (an SPList) is a valid instance of the correct list.
- Checked and re-checked the query in CAML builder

Note: This particular query should might (and will in my demo data) return no hits. However, I'd assume it would still return an object with a 0 value in the count property. Or am I mistaken about that?

  • 1
    Your CAML query is missing an angle bracket before /Value. – James Love Jun 14 '11 at 20:39
  • Did that fix it? I'll pop it in as an answer so can be marked correct. – James Love Jun 14 '11 at 20:40
  • Added anyway :) – James Love Jun 14 '11 at 20:42
  • It did fix it. I feel like a dolt for missing something so obvious, but I appreciate that sometimes fresh perspective is the best debugging tool. – JohnFx Jun 15 '11 at 0:27
  • Totally - CAML usually doesn't have intellisense so I know if there's CAML then the problem is there, the rest of the code is usually fine :) – James Love Jun 15 '11 at 6:31
3

Your CAML query is missing an angle bracket before /Value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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