比如我现在有个datatable数据结构如下name     id      pwd   (表头)张三     zs      123
李四     ls      111
张三     zs      452
王二     we      124
李四     ls      111
王二     we      122
张三     zs      455使用C#程序处理我想得到如下结果:
张三(3)  zs(3)  111(2)意思是我想得到DataTable的每列重复次数最多的数据,并得到重复多少次.

解决方案 »

  1.   


    你好我的意思是datatable是否自己有属性或者方法得到我想要的数据?   
    写循环判断是最无奈的方法.
      

  2.   

    好像GRIDVIEW有一个汇总的方法
    private double sum = 0;//取指定列的数据和,你要根据具体情况对待可能你要处理的是int
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
            if (e.Row.RowIndex >= 0)
            {
                sum += Convert.ToDouble(e.Row.Cells[6].Text);
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[5].Text = "总薪水为:";
                e.Row.Cells[6].Text = sum.ToString();
                e.Row.Cells[3].Text = "平均薪水为:";
                e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();
                
            }
        }类似这样的试试呢
      

  3.   

    declar @name varchar(50) @id varchar(20),@pwd varchar(6)
    select @name =count(张三),@id=count(zs),@pwd =count(111) from datatable