【转】dataset中删除重复数据

代码
/// <summary>
/// 获取对固定列不重复的新DataTable
/// </summary>
/// <param name="dt">含有重复数据的DataTable</param>
/// <param name="colName">需要验证重复的列名</param>
/// <returns>新的DataTable,colName列不重复,表格式保持不变</returns>
private DataTable GetDistinctTable(DataTable dt,string colName)
{
DataView dv
= dt.DefaultView;
DataTable dtCardNo
= dv.ToTable(true, colName);
DataTable Pointdt
= new DataTable();
Pointdt
= dv.ToTable();
Pointdt.Clear();
for (int i = 0; i < dtCardNo.Rows.Count; i++)
{
DataRow dr
= dt.Select(colName + "='" + dtCardNo.Rows[i][0].ToString() + "'")[0];
Pointdt.Rows.Add(dr.ItemArray);
}
return Pointdt;
}
转自:http:
//www.cnblogs.com/axcozy/archive/2009/12/29/1635496.html

 

posted @ 2010-04-16 14:17  哥本哈根  阅读(243)  评论(0编辑  收藏  举报