måndag 2 juni 2008

Basic SPQuery problems

I'm new to caml and SPQuery and I've build this simple search webpart for the Case Management project I'm on. And the frustration starts. I've used the U2U CAML Query Builder which is a really nice tool. Somehow all of the queries I've copied from that tool has returned all rows when using SPQuery and GetItems() on the list I want to select from. Turns out you have to remove the <QUERY>-tags.

Basic query with SPQuery

List<SPListItem> cases = new List<SPListItem>();

SPSite site = Helper.GetDefaultSite();

SPWeb web = site.OpenWeb();

SPList list = web.Lists["myCaseList"];

SPQuery query = new SPQuery();

query.Query = "<Where><Eq><FieldRef Name='ProblemType'/><Value Type='Text'>6</Value></Eq></Where>";

SPListItemCollection foundItems = list.GetItems(query);

if (foundItems.Count > 0)

foreach (SPListItem item in foundItems)

cases.Add(item);

caseList.Cases = cases;

Inga kommentarer: