SPQuery简单使用示例
通过SPQuery获得Score字段中大于等于60的列表条目,并且在这些条目的标题后加上“(合格)”字符串,然后再另一列表中,添加一个新条目,写入合格人数。
// 首先获取到SPWeb对象web
SPListCollection lists = web.Lists;
SPList scoreList = lists["Score"];
SPList passList = lists["Pass"];
SPQuery query = new SPQuery();
query.Query = "<Where><Geq><FieldRef Name='Score'/>" +
"<Value Type='Number'>60</Value></Geq></Where>";
SPListItemCollection items = scoreList.GetItems(query);
foreach(SPListItem item in items)
{
string title = item["Title"] + "(合格)";
item["Title"] = title;
item.Update();
}
SPListItem newItem = passList.Items.Add();
newItem["Count"] = items.Count;
newItem.Update();
SPListCollection lists = web.Lists;
SPList scoreList = lists["Score"];
SPList passList = lists["Pass"];
SPQuery query = new SPQuery();
query.Query = "<Where><Geq><FieldRef Name='Score'/>" +
"<Value Type='Number'>60</Value></Geq></Where>";
SPListItemCollection items = scoreList.GetItems(query);
foreach(SPListItem item in items)
{
string title = item["Title"] + "(合格)";
item["Title"] = title;
item.Update();
}
SPListItem newItem = passList.Items.Add();
newItem["Count"] = items.Count;
newItem.Update();