#region datatable去重 ////// datatable去重 /// ///需要去重的datatable ///public static DataTable GetDistinctTable(DataTable dtSource) { DataTable distinctTable = null; try { if (dtSource != null && dtSource.Rows.Count > 0) { string[] columnNames = GetTableColumnName(dtSource); DataView dv = new DataView(dtSource); distinctTable = dv.ToTable(true, columnNames); } } catch (Exception ee) { MessageBox.Show(ee.ToString()); } return distinctTable; } #endregion #region 獲取表中所有列名 public static string[] GetTableColumnName(DataTable dt) { string cols = string.Empty; for (int i = 0; i < dt.Columns.Count; i++) { cols += (dt.Columns[i].ColumnName + ,); } cols = cols.TrimEnd(','); return cols.Split(','); } #endregion