Sri*_*ddy 6 c# sorting datatable dataset
我有一个包含以下数据的数据集
Name Value Percent
0-3 months 0 0
3-12 months 0 0
1-5 years 1234.12 28
5-10 years 13144.11 68
10-15 years 0 0
Over 15 years 1233.44 14
Other Income 2245.12
Run Code Online (Sandbox Code Playgroud)
当我尝试
foreach (DataRow dr in dsMaturity.Tables[0].Select("name not like 'Other%'"))
{
TotalValue += double.Parse(dr["Value"].ToString());
}
Run Code Online (Sandbox Code Playgroud)
编辑:实际上,类似于上面的代码.我正在使用类似的循环将数据添加到显示存储桶,最终写入图表.
foreach (DataRow dr in dsMaturity.Tables[0].Rows)
{
//Add to the display bucket
}
Run Code Online (Sandbox Code Playgroud)
我得到的数据排序如下:
0-3 months
10-15 years
1-5 years
3-12 months
5-10 years
Over 15 years
Run Code Online (Sandbox Code Playgroud)
为什么?如何将数据排除?这是至关重要的,因为我在图表对象中显示数据.我在这里错过了什么吗?
尝试:
foreach (DataRow dr in dsMaturity.Tables[0].Select("name not like 'Other%'", "column_to_sort_by"))
{
TotalValue += double.Parse(dr["Value"].ToString());
}
Run Code Online (Sandbox Code Playgroud)
其中column_to_sort_by是按正确顺序排序的列。
| 归档时间: |
|
| 查看次数: |
3711 次 |
| 最近记录: |