在计算编号时我必须使用什么方法。数据集中的男性和女性?

问题描述 投票:-4回答:1

所以我正在处理RDLC报告,我想要的是计算公司中有多少男性和女性。

enter image description here

这是我获得公司独特价值的代码

            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();

正如您所看到的,我列出了一个独特的公司列表,并想要计算特定公司中有多少男性和女性。

c# sql rdlc
1个回答
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();
© www.soinside.com 2019 - 2024. All rights reserved.