MOSS 关于SPQuery 和SPSiteDataQuery的区别好用法!
下面的代码是给在做MOSS开发的同行们的一些对象模型的学习,和自己的看法
MOSS 关于SPQuery 的用法,是关于列表的查询范围比较的小。。
SPWeb web = (new SPSite(" http://moss/sites/hello")).OpenWeb ();
SPList list = web.Lists["test"];
SPQuery query = new SPQuery();
query.Query = "
4
";
SPListItemCollection items = list.GetItems(query);
foreach(SPListItem item in items)
Console.WriteLine(item.DisplayName);
SPSiteDataQuery的是查询整个Site的范围比SPQuery大,我就不在这里罗嗦拉,大家看拉代码测试一下,就很明白拉
SPWeb web = (new SPSite(" http://moss/sites/hello")).OpenWeb ();
SPSiteDataQuery query = new SPSiteDataQuery();
query.Query = "
4
";
query.Lists = "
";
query.Webs = "";
query.ViewFields = "
";
DataTable dt = web.GetSiteData(query);
Console.WriteLine(dt.Rows.Count);
希望对各位有帮助!!!
MOSS 关于SPQuery 的用法,是关于列表的查询范围比较的小。。
SPWeb web = (new SPSite(" http://moss/sites/hello")).OpenWeb ();
SPList list = web.Lists["test"];
SPQuery query = new SPQuery();
query.Query = "
SPListItemCollection items = list.GetItems(query);
foreach(SPListItem item in items)
Console.WriteLine(item.DisplayName);
SPSiteDataQuery的是查询整个Site的范围比SPQuery大,我就不在这里罗嗦拉,大家看拉代码测试一下,就很明白拉
SPWeb web = (new SPSite(" http://moss/sites/hello")).OpenWeb ();
SPSiteDataQuery query = new SPSiteDataQuery();
query.Query = "
query.Lists = "
query.Webs = "
query.ViewFields = "
DataTable dt = web.GetSiteData(query);
Console.WriteLine(dt.Rows.Count);
希望对各位有帮助!!!