SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am going to use linq to get datapoints for chart created in sharepoint from datatable

this is datatable with 2 columns "task" and "users"
task users
task 1 john
task 2 mike, jim
task 3 john, mike
task 4 jack

I need a dictionary object filled with value like this
john 2
jim 1
mike 2
jack 1

How to proceed? thanks.

share|improve this question
Are you going to be using Silverlight charts? in which case you need to use the Sharepoint client object model for Silverlight. – Fox Feb 10 '12 at 7:00
Please tell us whether it's Silverlight or ASP.NET and also which version of Sharepoint? – Fox Feb 10 '12 at 7:06
its going to be because I'm not going to use silverlight ever :) Its a sandboxed project so I'm worried about peformance, I can obviously use for loop or something to get data the way I want but I think linq will be more optimized. – techie Feb 10 '12 at 12:56

Ok, I've written an example which should sort out out. Just a note that this is not really a Sharepoint related question but more a Linq/Data Question. Anyways, this should do it :

internal class Program
    private static void Main(string[] args)
        DataTable demodatatTable =  CreateDemoDataTable();            

        var JohnTasks = demodatatTable.AsEnumerable().Where(z=>z.Field<List<string>>("Users").Contains("John"));

        Console.WriteLine("John Tasks : " + JohnTasks.Count());
    private static DataTable CreateDemoDataTable()
        System.Data.DataTable d = new System.Data.DataTable("MyDataTable");

        d.Columns.Add("Task", typeof(string));
        d.Columns.Add("Users", typeof(List<string>));

        List<string> users1 = new List<string>();
        d.Rows.Add("Task1", users1);

        List<string> users2 = new List<string>();
        d.Rows.Add("Task2", users2);

        return d;

share|improve this answer
You are finding just one person's task but thats not what is required. I need to get count of all persons task like the result I have shown. anyways, thanks for helping. – techie Feb 20 '12 at 19:55

In your Scenario, because you're using ASP.NET , you can use Linq to Sharepoint to create IQueryable<> or List<> collections.

Here is a good example of how to use Linq to Sharepoint 2010.

share|improve this answer
I don't want to use linq to sharepoint, just pure linq applied to datatable would be better. List is not fixed, there can be different columns so its difficult. If you know how to do it from datatable, please guide. – techie Feb 14 '12 at 8:09
Ok, Where is the data coming from that will be populating your datatable? Is this another database outside of Sharepoint? You cannot use Datatables and SQL Commands with a Sharepoint database. – Fox Feb 16 '12 at 11:07
Lets jus say I have that data in the datatable. I wand linq to generate the result like I mentioned. If thats possible please guide me. Do not worry about where data comes from or whether I can use it with SharePoint db or not. Just let me know if the result can be obtained if the data is in a 'DataTable' object and I want result like I mentioned! – techie Feb 16 '12 at 14:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.