导航

[DataTable]C# datatable取最大值最小值

Posted on 2014-03-22 21:11  beeone  阅读(8882)  评论(0编辑  收藏  举报
ArrayList al = new ArrayList();
        DataTable dt = new DataTable();
        dt.Columns.Add("A",typeof(double));
        dt.Columns.Add("B", typeof(double));
        dt.Columns.Add("C", typeof(double));
        DataRow dr1 = dt.NewRow();
        dr1["A"] = 5.5;
        dr1["B"] = -20.6;
        dr1["C"] = -3.8;
        dt.Rows.Add(dr1);

        for (int i = 0;i< dt.Rows.Count;i++)
        {
            al.Add(Convert.ToDouble( dt.Rows[i]["A"]));
            al.Add(Convert.ToDouble(dt.Rows[i]["B"]));
            al.Add(Convert.ToDouble(dt.Rows[i]["C"]));
        }
        al.Sort();
        Response.Write(al[al.Count - 1].ToString()+"<br/>");//最大值
        Response.Write(al[0].ToString());//最小值