2010-07-28 54 views
1

我正在嘗試使用this implementation of a DataSetHelper按列對數據集進行分組。SelectGroupByInto不是分組!

我在做什麼是:

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是這樣的:

用戶 ------ 時間

John- ----- 0.6

馬克------ 1.2

保羅------ 7.1

約翰------ 52.6

約翰------ 0.8

保羅------ 50.3

最後,dt_tmp應該有這樣的:

用戶 ------ 時間

約翰------ 54.0

馬克------ 1.2

保羅------ 57.4

但是我所得到的是這樣的:

用戶 ------ 時間

約翰------ 0.6

約翰------ 52.6

約翰------ 0.8

馬克------ 1.2

保羅------ 7.1

保羅------ 50.3

因此,它似乎沒有做這個總和(時間)。

會發生什麼?

在此先感謝。

回答

1

哇,我從來沒有想過這將是一個DataSetHelper類中的錯誤。它似乎有一些數值的問題。

功能ColumnEqual應改爲:

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 
} 

所不同的是在a.ToString()== b.ToString(),即淵源是==灣

無論如何,謝謝!