DataTable中获取分数的最大值
1、创建DataTable并赋值
DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Score", typeof(double)); //设置datable主键列 dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] }; #region 添加数据 DataRow dr = null; for (int i = 0; i < 10; i++) { dr = dt.NewRow(); dr["ID"] = 100 + i.ToString(); dr["Name"] = "Name" + i.ToString(); dr["Score"] = (i + 1) * 30; dt.Rows.Add(dr); } #endregion
2、找出DataTable中分数的最大值
double maxScore = 0; double.TryParse(dt.Compute("Max(Score)", "").ToString(), out maxScore);// 取得datable中Score的最大值 DataRow row = dt.Select("Score=" + maxScore)[0];
3、修改最大分数值
row["Score"] = 100000000.12;