一些常用的方法(1)--去除DataTable中的重复数据

时间:2023-03-09 09:35:01
一些常用的方法(1)--去除DataTable中的重复数据

private DataTable Display(DataTable dtSource)
        {
            DataTable dtTemp = dtSource.Copy();
            foreach (DataRow dr in dtSource.Rows)
            {
                DataRow[] drRepeat = dtTemp.Select("AA='" + dr["AA"].ToString().Trim() + "' and BB='" + dr["BB"].ToString().Trim() + "'");
                if (drRepeat.Length > 1)
                {
                    for (int i = 0; i < drRepeat.Length - 1; i++)
                    {
                        dtTemp.Rows.Remove(drRepeat[i]);
                    }
                }
            }
            return dtTemp;
        }