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.
Example
Column A Column B
1 Admin
2 Approver
2 Deletion
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,
Please take a look and let me know if this count for linq, the thing is that I’m just using dataTable.Select("ID = " & idTolook) but not where or those type of things lol.
.3. RPA Challenge - LINQ to extract values from datatable.zip (3.2 KB)
With CSV file saved and having the first cell filled with string : ID - there is issue to reopen csv file - it looks for sylk file and the content is messed up.
Thank you for your post! Since I was unable to find any c# code to accomplish something similar…I am providing an example of getting the Sum of a column in a DataTable.