The DataTable’s Compute method

The DataTable’s Compute method

The DataTable class has a method, Compute, that executes SQL-like functions on the rows locally stored in the DataTable. It supports functions such as COUNT, SUM, MIN, MAX, AVG and others. Here’s an example to calculate the average salary for the employees stored in the tableEmployees DataTable:

Dim maxSalary As Integer = CType(tableEmployees.Compute("AVG(Salary)", ""), _    Integer)

The Compute method takes in a second parameter, which is a filter expression. For example, this is how to calculate the number of employees with a salary greater than $5,000:

Dim numLuckyEmployees As Integer = CType(tableEmployees.Compute _    ("COUNT(EmployeeID)", "Salary > 5000"), Integer)

See also  Who are the Modern GPU Cloud Providers?

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist