Generally, By using the CAML Query in SharePoint we doesn't have a Option to get the Unique/distinct Values from the List
By using the DataView we can achieve this.
The following example will demonstrate about this:
SPQuery oQuery=new SPQuery()
oQuery.Query="--------------------";//Your Query to get the values from the List
DataTable dtGeneral=new DataTable();
dtGeneral=listObject.GetItems(oQuery).GetDataTable();
DataView dvUnique=new DataView(dtGeneral);
dvUnique.Sort="Column1";//Sorting the View by using the Column
DataTable dtUnique=new DataTable();
dtUnique=dvUnique.ToTable(true,"Column1");
Here dvUnique.ToTable(true,"Column1"); will give the Unique values of the "Column1" from the List.
By using the DataView we can achieve this.
The following example will demonstrate about this:
SPQuery oQuery=new SPQuery()
oQuery.Query="--------------------";//Your Query to get the values from the List
DataTable dtGeneral=new DataTable();
dtGeneral=listObject.GetItems(oQuery).GetDataTable();
DataView dvUnique=new DataView(dtGeneral);
dvUnique.Sort="Column1";//Sorting the View by using the Column
DataTable dtUnique=new DataTable();
dtUnique=dvUnique.ToTable(true,"Column1");
Here dvUnique.ToTable(true,"Column1"); will give the Unique values of the "Column1" from the List.
0 comments:
Post a Comment