• DataTable去重


      #region datatable去重
            /// <summary>
            /// datatable去重
            /// </summary>
            /// <param name="dtSource">需要去重的datatable</param>
            /// <param name="columnNames">依据哪些列去重</param>
            /// <returns></returns>
            public static DataTable GetDistinctTable(DataTable dtSource, params string[] columnNames)
            {
                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)
                {
                }
                return distinctTable;
            }
    
            /// <summary>
            /// datatable去重
            /// </summary>
            /// <param name="dtSource">需要去重的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)
                {
                }
                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
  • 相关阅读:
    【实战】如何实现滚轮时间的显示
    NSDate的常用用法
    UIDatePicker的简单用法
    NSDateFormatter相关整理
    UIPickerView
    回家任务
    addTarget:self 的意思是说,这个方法在本类中
    2020/2/25
    树上启发式合并
    题解
  • 原文地址:https://www.cnblogs.com/Cein/p/7657159.html
Copyright © 2020-2023  润新知