views:

23

answers:

1

Hi people. I'm trying to use this implementation of a DataSetHelper to group a DataSet by a column.

What I'm doing is:

DataSet ds_tmp = new DataSet();
DataTable dt_tmp;
ds_tmp.Tables.Add(data_table_UserTime);
dsHelper = new DataSetHelper(ref ds_tmp);
dt_tmp = dsHelper.SelectGroupByInto("UniqueUsers", ds_tmp.Tables[0], "User, sum(Time) TotalTime", "Time>0", "User");

data_table_UserTime is something like this:

User------Time

John------0.6

Mark------1.2

Paul------7.1

John------52.6

John------0.8

Paul------50.3

At the end, dt_tmp should have this:

User------Time

John------54.0

Mark------1.2

Paul------57.4

But what I get is this:

User------Time

John------0.6

John------52.6

John------0.8

Mark------1.2

Paul------7.1

Paul------50.3

So it seems it is not doing the sum(Time).

What can be happening?

Thanks in advance.

A: 

Wow, I never thought it would be a bug in the DataSetHelper class. It seems it has some problems with numeric values.

The function ColumnEqual should be changed to:

private bool ColumnEqual(object a, object b)
{
    /*
     * Compares two values to see if they are equal. Also compares DBNULL.Value.
     *
     * Note: If your DataTable contains object fields, you must extend this
     * function to handle them in a meaningful way if you intend to group on them.
    */
    if ((a is DBNull) && (b is DBNull))
        return true;    //both are null
    if ((a is DBNull) || (b is DBNull))
        return false;    //only one is null
    return (a.ToString() == b.ToString());    //value type standard comparison
}

The difference is in a.ToString() == b.ToString(), that originaly was a==b.

Thanks anyway!

Tronfi