C# SelectGroupByInto不是分组!
我正在尝试使用按列对数据集进行分组 我正在做的是:C# SelectGroupByInto不是分组!,c#,.net,database,datatable,dataset,C#,.net,Database,Datatable,Dataset,我正在尝试使用按列对数据集进行分组 我正在做的是: 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) TotalT
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");
数据表用户时间是这样的:
用户---时间
约翰------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
因此,它似乎没有做总和(时间)
会发生什么
提前谢谢。哇,我从没想过这会是DataSetHelper类中的一个bug。它似乎在数值方面有一些问题 函数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(),原来是a==b
无论如何谢谢你 哇,我从没想过这会是DataSetHelper类中的一个bug。它似乎在数值方面有一些问题 函数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(),原来是a==b
无论如何谢谢你