What is the best way to retrieve distinct / unique values using SPQuery?

前端 未结 6 968
孤独总比滥情好
孤独总比滥情好 2020-12-30 04:03

I have a list that looks like:

Movie          Year
-----          ----
Fight Club     1999
The Matrix     1999
Pulp Fiction   1994

Using CA

6条回答
  •  -上瘾入骨i
    2020-12-30 05:03

    Can you switch from SPQuery to SPSiteDataQuery? You should be able to, without any problems.

    After that, you can use standard ado.net behaviour:

    SPSiteDataQuery query = new SPSiteDataQuery();
    /// ... populate your query here. Make sure you add Year to the ViewFields.
    
    DataTable table = SPContext.Current.Web.GetSiteData(query);
    
    //create a new dataview for our table
    DataView view = new DataView(table);
    
    //and finally create a new datatable with unique values on the columns specified
    
    DataTable tableUnique = view.ToTable(true, "Year");
    

提交回复
热议问题