1 /// <summary> 2 /// 获取对固定列不重复的新DataTable 3 /// </summary> 4 /// <param name="dt">含有重复数据的DataTable</param> 5 /// <param name="colName">需要验证重复的列名</param> 6 /// <returns>新的DataTable,colName列不重复,表格式保持不变</returns> 7 private DataTable GetDistinctTable(DataTable dt, string colName) 8 { 9 DataView dv = dt.DefaultView; 10 DataTable dtCardNo = dv.ToTable(true, colName); 11 DataTable Pointdt = new DataTable(); 12 Pointdt = dv.ToTable(); 13 Pointdt.Clear(); 14 for (int i = 0; i < dtCardNo.Rows.Count; i++) 15 { 16 DataRow dr = dt.Select(colName + "='" + dtCardNo.Rows[i][0].ToString() + "'")[0]; 17 Pointdt.Rows.Add(dr.ItemArray); 18 } 19 return Pointdt; 20 }