Get distinct/unique values from CAML Query

Many times, we face a challenge to get unique rows from a CAML query. The problem is CAML query does not have any feature to get the distinct rows. Luckily the Data View has a method to return a Table with distinct rows.

DataView.ToTable(Bool isDistinct, string columnName);

This will return a table with distinct values based on the column name given in the method.

Below is an example how to use this along with the CAML query

query.Query = strQuery;
itemColl = lst.GetItems(query);
dtInOut = itemColl.GetDataTable();
dvInOut = new DataView(dtInOut);
dvInOut.Sort = “Token_x0020_Number Asc”;
dtInOut = dvInOut.ToTable(true, “Token_x0020_Number”);

Here dvInOut.ToTable method will give values from the list with distinct Token_x0020_Number values.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a website or blog at

Up ↑

%d bloggers like this: