Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

SPQuery search of a portal list

  Asked By: Colt    Date: Sep 07    Category: Sharepoint    Views: 1189

I am trying to do an SPQuery search of a portal list, and I am getting some unusual results. I want to look in a list called Job Codes for all matches whose job code description contains a certain string. The code I am using seems to be returning all of the results in the list, not just the matches.

Any ideas what I might be doing wrong?

Below is the code that I am using:

SPWeb site = SPControl.GetContextWeb(Context);

SPList list = site.Lists["Job Codes"];

SPQuery query = new SPQuery();

query.Query = SPEncode.HtmlEncode("<Where><Contains><FieldRef Name='Job Code Description'/><Value Type='Text'>AEW</Value></Contains></Where>");

SPListItemCollection items = list.GetItems(query);

if (items.Count > 1) {
outputText += "<table>";

foreach (SPListItem item in items) {
outputText += "<tr>";
outputText += "<td>" + SPEncode.HtmlEncode(item["Job Code"].ToString()) + "</td>";
outputText += "<td>" + SPEncode.HtmlEncode(item["Job Code Description"].ToString()) + "</td>";
outputText += "</tr>";

if (items.Count > 1) {
outputText += "</table>";



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on SPQuery search of a portal list Or get search suggestion and latest updates.