-1

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.

3
  • 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, 2012 at 7:00
  • Please tell us whether it's Silverlight or ASP.NET and also which version of Sharepoint?
    – Fox
    Feb 10, 2012 at 7:06
  • its going to be asp.net 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, 2012 at 12:56

2 Answers 2

1

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());
        Console.ReadLine();
    }
    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>();
        users1.Add("John");
        users1.Add("Peter");
        d.Rows.Add("Task1", users1);


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

        return d;
    }

}
1
  • 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, 2012 at 19:55
0

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.

http://www.zimmergren.net/technical/sp-2010-getting-started-with-linq-to-sharepoint-in-sharepoint-2010

3
  • 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, 2012 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, 2012 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, 2012 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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