DataTable dt = new DataTable(); sql.Append(" SELECT a from b "); dt = SqlHelper.GetDataTable(sql.ToString());
sql = new StringBuilder(); sql.Append(" SELECT c from d "); var jcdt = SqlHelper.GetDataTable(sql.ToString()); //重要 DataColumn dataColumn1 = new DataColumn("自定义字段名称", typeof(Int32)); DataColumn dataColumn2 = new DataColumn("自定义字段名称", typeof(Int32)); dt.Columns.Add(dataColumn1); dt.Columns.Add(dataColumn2); //给新增的字段赋值 foreach (DataRow item in dt.Rows)//item:行 相当于dr { DataRow[] num = jcdt.Select("ID=" + item[0]);//根据某个字段查询的数据 item:行 【0】:列 item[5] = num.Count(); int i = num.Count(); DataRow[] hg = jcdt.Select("ID=" + item[0] + "and VerID=1"); item[6] = hg.Count(); item[7] = num.Count() - hg.Count(); item[8] = num.Count() > 0 ? (Convert.ToDecimal(hg.Count()) / Convert.ToDecimal(num.Count()) * 100).ToString("f2") + "%" : "0.00%"; } return format.ResultJsonData("SUCCESS", "获取信息成功!", dt);
标签:Count,自定义,C#,item,num,sql,dt,datatable From: https://www.cnblogs.com/fuyao/p/17664275.html