所以我正在处理RDLC报告,而我想要的是计算公司中有多少男性和女性。
这是我获得公司独特价值的代码
ReportsData m = new ReportsData();
SqlDataAdapter da = new SqlDataAdapter("SELECT DISTINCT Company FROM TBL_Users WHERE Course = '" + cmbCourse.Text + "' ", con);
DataTable dt = new DataTable();
da.Fill(m, m.Tables[0].TableName);
ReportDataSource rds = new ReportDataSource("CompData", m.Tables[0]);
this.rpvSL.LocalReport.Refresh();
this.rpvSL.RefreshReport();
ReportsData ma = new ReportsData();
SqlDataAdapter daa = new SqlDataAdapter("SELECT * FROM TBL_Users WHERE Course = '" + cmbCourse.Text + "' ", con);
daa.Fill(ma, ma.Tables[0].TableName);
ReportDataSource rdsa = new ReportDataSource("StudentData", ma.Tables[0]);
this.rpvSL.LocalReport.DataSources.Clear();
this.rpvSL.LocalReport.DataSources.Add(rds);
this.rpvSL.LocalReport.DataSources.Add(rdsa);
this.rpvSL.LocalReport.Refresh();
this.rpvSL.RefreshReport();
正如您所看到的,我列出了一个不同的公司列表,并希望计算特定公司中有多少男性和女性。
答案 0 :(得分:0)
尝试以下操作:
var results = dt.AsEnumerable()
.GroupBy(x => x.Field<string>("Company"))
.Select(x => new { company = x.Key, employes = x.Count(), male = x.Where(y => y.Field<string>("Gender") == "M").Count(), female = x.Where(y => y.Field<string>("Gender") == "F").Count() })
.ToList();