#region DataTable to Heavy///<summary>//DataTable to///</summary>/<param NA Me= "Dtsource" > Need to go to the heavy datatable</param>//<param name= "ColumnNames" > based on which column to weight </param>// <returns></returns> public static DataTable getdistincttable (DataTable dtsource, params string[] Column Names) {DataTable distincttable = Dtsource.clone (); try {if (dtsource! = null && dtSource.Rows.Count > 0) { DataView dv = new DataView (dtsource); distincttable = dv. ToTable (True, columnnames); }} catch (Exception ee) {MessageBox.Show (EE. ToString ()); } return distincttable; }///<summary>//DataTable Go heavy///</summary>//<param name= "Dtsource" > Required Go to the Heavy datatable</param>//<returns></returns> 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 Get all the column names in the table 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
The above is the C # DataTable data deduplication content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!