Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Mar 17, 2003

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)
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap