承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

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 = "<Where><Contains><FieldRef Name='Title'/><Value Type='Text'>4</Value></Contains></Where>";
                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 = "<Where><Contains><FieldRef Name='Title'/><Value Type='Text'>4</Value></Contains></Where>";
                query.Lists = "<Lists BaseType='0' />";
                query.Webs = "<Webs Scope='Recursive' />";
                query.ViewFields = "<FieldRef Name='Title' /><ProjectProperty Name='Title' /><ListProperty Name='Title' />";
                DataTable dt = web.GetSiteData(query);
                Console.WriteLine(dt.Rows.Count);
希望对各位有帮助!!!

posted on 2007-06-14 10:13  A A  阅读(3030)  评论(6编辑  收藏  举报