您的位置:首页 > 其它

对DataTable进行Distinct

2007-03-14 21:51 501 查看
DataTable priceDetailDistinctTable = m_PriceDetailDataTable.DefaultView.ToTable(true,
new String[] { "vendor_id", "vendor_code", "vendor_name", "vendor_site" });

来自:

选择DataTable中的唯一值(Distinct)

开发中经常用到筛选DataTable等数据源中的唯一值(类似SQL中Distinct的返回结果),在.NET FX 1.x下我是这写的:
1static DataTable SelectDistinct(string ReturnTableName, DataTable SourceTable, string ReturnFieldName, string AdditionalFilterExpression)
2
19static bool ColumnEqual(object A, object B)
20
后来这样写:

1private DataTable SelectDistinct(DataTable sourceTable, string sourceColumn)
2
33

再后来又这样写:

1object[] distinctRoomType = GetDistinctValues(dt,"Roomtype");
2
3Here is the method definition.
4
5public object[] GetDistinctValues(DataTable dtable,string colName)
6
现在.NET FX 2.0中只要一句就可以搞定了,方便了许多:
1DataTable d = dataSetName.dataTableName.DefaultView.ToTable(true, new string[] { "ColumnName" });
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: