Wednesday, December 29, 2010

Progress Bar and Threading in C# .NET

Hi,
Adding a progress bar and updating it without freezing the main UI Form has always been tough for many .NET programmers. Here is a skeleton (demo) application on how to update progress bar on the main window from a secondary thread. This is a skeleton application which you can use as such just by inserting your code snippet in the right place.

Download Source Code (Visual Studio 2008 Project)

You can download and modify the source code for any purpose free of cost.

Wednesday, December 1, 2010

"GROUP BY" does not group some data - Why?


"GROUP BY" clause (tested in PostgreSQL) does not group rows by on-the-fly temporary columns included in SELECT statement. For example, the below SQL will not group properly since 'manager_name' column is included in 'GROUP BY'. But, removing it from 'GROUP BY' will work properly.

Erroneous sql:
SELECT
    emp.name,
    salary.year,
    SUM(salary.amount),
    'Ela' as manager_name -- On the fly temporary column
FROM
    emp
JOIN
   salary ON salary.emp_id = emp.id
GROUP BY   
    emp.name,
    salary.year,
    manager_name -- <-- Here is the problem! This should be removed.
ORDER BY
    emp.name,
    salary.year;   
Corrected SQL:
SELECT
    emp.name,
    salary.year,
    SUM(salary.amount),
    'Ela' as manager_name
FROM
    emp
JOIN
   salary ON salary.emp_id = emp.id
GROUP BY   
    emp.name,
    salary.year
ORDER BY
    emp.name,
    salary.year;