1 using (OracleConnection con = new
OracleConnection(ConfigurationManager.AppSettings[\"ConnectionString\"].ToString())) 2 {
3 con.Open();
4 OracleCommand cmd = con.CreateCommand(); 5 cmd.CommandText = \"SELECT * FROM EMP\";
6 OracleDataAdapter oda = new OracleDataAdapter(cmd); 7 DataSet ds = new DataSet(); 8 oda.Fill(ds);
9 DataTable dt = ds.Tables[0]; 10 //求和
11 string sum = Math.Round(Convert.ToDouble(dt.Compute(\"sum(sal)\", \"\")), 2).ToString();
12 //求平均
13 string avg = Math.Round(Convert.ToDouble(dt.Compute(\"avg(sal)\", \"\")), 2).ToString();
14 //具有筛选条件 求和
15 string sumFilter = Math.Round(Convert.ToDouble(dt.Compute(\"sum(sal)\", \"SAL<3000\")), 2).ToString();
16 //具有筛选条件 求平均
17 string avgFilter = Math.Round(Convert.ToDouble(dt.Compute(\"avg(sal)\", \"SAL<3000\")), 2).ToString(); 18 //标准偏差
19 string stDev = Math.Round(Convert.ToDouble(dt.Compute(\"stdev(sal)\", \"\")), 2).ToString();
20 //具有筛选条件标准偏差
21 string stDevFilter = Math.Round(Convert.ToDouble(dt.Compute(\"stdev(sal)\", \"sal<3000\")), 2).ToString(); 22 //最小值
23 string min = dt.Compute(\"min(sal)\", \"\").ToString(); 24 //具有筛选条件的最小值
25 string minFiter = dt.Compute(\"min(sal)\", \"sal<3000\").ToString();
26 //平均值+标准偏差 27 string avgStDev =
Math.Round(Convert.ToDouble(dt.Compute(\"avg(sal)+stdev(sal)\", \"\")), 2).ToString(); 28 dt.Columns.Add(\"cl\", typeof(string),\"len(ename)\"); 29 StringBuilder sb = new StringBuilder(); 30 sb.Append(\"求和:\" + sum + \"
\"); 31 sb.Append(\"求平均:\" + avg + \"
\"); 32 sb.Append(\"标准偏差:\" + stDev + \"
\"); 33 sb.Append(\"最小值:\" + min + \"
\");
34 sb.Append(\"具有筛选条件求和:\"+sumFilter+\"
\"); 35 sb.Append(\"具有筛选条件求平均:\"+avgFilter+\"
\");
36 sb.Append(\"具有筛选条件标准偏差:\"+stDevFilter+\"
\"); 37 sb.Append(\"具有筛选条件的最小值:\"+minFiter+\"
\"); 38 sb.Append(\"平均值+标准偏差:\"+avgStDev+\"
\"); 39 lbShow.Text = sb.ToString(); 40 }
因篇幅问题不能全部显示,请点此查看更多更全内容