DataTable dt = QueryUtil.GetDataResult(sql);
            
                DataView myDataView = new DataView(dt);
                string[] strComuns = { "KIND_ID", "StyleCount" };//此处可加任意数据项组合
                dt = myDataView.ToTable(true, strComuns);                 this.Repeater1.DataSource = dt.DefaultView; 
                this.Repeater1.DataBind();  
在网上找了 中间那三行代码 说是过滤重复数据的。  但是没有用呀  大家帮忙看看 小弟急啊        

解决方案 »

  1.   

    /// <summary>
            /// 去除重复行
            /// </summary>
            /// <param name="dt">DataTable</param>
            /// <param name="con">要显示的字段</param>
            /// <returns></returns>
            public static DataTable ToDistinct(this DataTable dt,string[] con){
                return dt.DefaultView.ToTable(true,con);//注:其中ToTable()的第一个参数为是否DISTINCT        }
      

  2.   

    如果你要是能写sql,那样的话更好些
      

  3.   

    我的DT  从数据库里读取出来 要进行 一定的处理    所以不能直接SQL
      

  4.   

    void DeleteSameRow(DataSet ds)
        {
            ArrayList indexList = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count-1; i++)
            {
                if (!IsContain(indexList, i))
                {
                    for (int j = i + 1; j < ds.Tables[0].Rows.Count; j++)
                    {
                        if (ds.Tables[0].Rows[i][AccountInfo.Columns.AUName].ToString() == ds.Tables[0].Rows[j][AccountInfo.Columns.AUName].ToString())
                        {
                            indexList.Add(j);
                        }
                    }
                }
            }
            for (int i = indexList.Count - 1; i >= 0; i--)
            {
                int index = Convert.ToInt32(indexList[i]);
                ds.Tables[0].Rows.RemoveAt(index);
            }
        }
        bool IsContain(ArrayList indexList, int index)
        {
            for (int i = 0; i < indexList.Count; i++)
            {
                int tempIndex = Convert.ToInt32(indexList[i]);
                if (tempIndex == index)
                {
                    return true;
                }
            }
            return false;
        } public DataTable SelectDistinct(DataTable SourceTable, string FieldName)
           {
                DataTable dt = new DataTable();
                for (Int32 i = 0; i < SourceTable.Columns.Count; i++)
                {
                  string fieldName=SourceTable.Columns[i].Caption;
                    dt.Columns.Add(fieldName, SourceTable.Columns[fieldName].DataType);
               }
                DataRow dataRow = dt.NewRow();
                foreach (DataRow dr in SourceTable.Select("", FieldName))
               {
                   if (dataRow == null || !(ColumnEqual(dataRow[FieldName], dr[FieldName])))
                   {
                       dataRow=dr;
                        DataRow row = dt.NewRow();
                       for (int i = 0; i < dataRow.ItemArray.Length; i++)
                        {
                            row[i] = dataRow[i];
                        }
                       dt.Rows.Add(row);
                   }
               }
                return dt;
           }
    参考
      

  5.   

    DataTable d = dataSetName.dataTableName.DefaultView.ToTable(true, new string[] { "ColumnName" });
      

  6.   

    //数据表 DataTable dt
    //建立临时表 DataTable dt1
    ViewState["ID"]="";for(int i=0 ; i<dt.Row.Counts ; i++)
    {
       if( ViewState["ID"].ToString().IndexOf(""+dt.Row[i]["ID"].ToString()+"") < 0 )
           {
              ViewState["ID"]  += dt.Row[i]["ID"].ToString() + "|";          //dt1中添加dt.Row[i]["ID"]的数据
           }
    }
      

  7.   

    如何对 DataTable 执行 SELECT DISTINCT http://www.cnblogs.com/jinglecat/articles/820339.html
      

  8.   

    DataView two = new DataView(one);
                two.Sort = "id";
    DataTable newTable = two.ToTable(true,"id","key","value");
      

  9.   

    感谢dazhabai
       终于解决了
      

  10.   

    那个,用IEnumable,这个接口,可以否