Can someone help me with how to extract values from datatable using LINQ. I have a csv which I am reading and creating a datatable. CSV has two columns A and B. Column A defines ID’s and column B defines role.
Column A Column B
and so on… ID 2 can have multiple values defined as role.
I can do that with other method but want to know with use of LINQ.
Please not that they were deliberately not allowed on DataTables, it’s just that DataTables pre-date the IQueryable and generic IEnumerable constructs on which Linq queries can be performed.
Both interfaces require some sort type-safety validation. DataTables are not strongly typed. This is the same reason why people can’t query against an ArrayList, for example.Query DataTable using LINQ in C#
For Linq to work you need to map your results against type-safe objects and query against that instead.
You can check this article as well:, May be it will help you on this.
ID : 1 Role in company : Analyst,
ID : 2 Role in company : Medical,Engineer,Accountant,IT,Specialist,
ID : 3 Role in company : Analyst,
ID : 4 Role in company : Scientist,Advisor,
ID : 5 Role in company : Scientist,