0

I have a datatable in my vb .net solution. let's say the datatable (let's call it MyTable) has 2 columns: Emp_id and Emp_cost.
I want to calculate the sum of Emp_cost for a specific Emp_id. For example, in the example below I want to get 1500 as Emp_cost for Emp_id = "1210". I wanted to use LINQ however, data stored in the Emp_cost column are in string format. Is there anyway to use LINQ (instead of using For) for calculation the total cost? (or something like: MyTable.Compute("Sum(Emp_cost)", "Emp_id = 1210")?

Emp_id Emp_cost
1210 500
1210 1000
1220 100
Sergey Nazarov
  • 671
  • 3
  • 15
Rodney
  • 1
  • 1
  • 3
    Convert your database Emp_id to INT and Emp_cost to DECIMAL. That is going to fix this problem, and many many more you are about to have. – Dour High Arch May 05 '21 at 18:45
  • Thanks for the quick response, would you please let me know how to convert data already exist in a datatable to another format? – Rodney May 05 '21 at 18:51
  • Consult [How to ALTER multiple columns at once?](https://stackoverflow.com/questions/3465560/) – Dour High Arch May 05 '21 at 19:02

0 Answers0