报告只显示一条记录,而DataTable有许多记录

本文关键字:记录 DataTable 许多 显示 一条 报告 | 更新日期: 2023-09-27 18:18:41

我在c#项目中使用ReportViewer。在显示每月员工流动率的报告时,我有一个问题。

问题是即使我的DataTable填充了几个记录,报告只显示了一个记录。

这是报告后面的查询…

//To get all months in the given period (from @startDate to @endDate)
    WITH x AS 
    (
    SELECT CAST(@startDate AS DATE) AS Months
    UNION ALL
    SELECT DATEADD(m, 1, Months) AS Months 
    FROM x 
    WHERE (Months < @endDate)
    )
    , 
//Here I use GETNOOFEMPS() function to get the no of active employees which were in the month
    y AS                        
    (
    SELECT Months, CAST(dbo.GETNOOFEMPS(Months) AS DECIMAL(9, 2)) AS NoEmpsAtBegining, CAST(dbo.ETOR(DATEADD(s, - 1, DATEADD(mm, DATEDIFF(m, 0, Months) + 1, 0))) 
    AS DECIMAL(9, 2)) AS NoEmpsAtEnd
    FROM x 
    )
//Calculate the ratio. This returns [Month|Emps at Begining | Emps at End | resigned | Ratio]
SELECT CONVERT(DATE, Months) AS [Month], NoEmpsAtBegining, NoEmpsAtEnd, dbo.GetResignEmployees(Months) AS NoEmpsResigned, 
CAST(dbo.GetResignEmployees(Months) / ((NoEmpsAtBegining + NoEmpsAtEnd) / 2) * 100 AS DECIMAL(9, 2)) AS EmployeeTurnOverRatio
FROM y 

即使我在DataAdapters查询生成器中运行它,它的运行也会给出所需的输出。但是当我在RDLC中使用它然后查看报告后,它只显示一条记录!

请问如何解决这个问题?

这是我对报告的看法……

    private void btnShowReport_Click(object sender, EventArgs e)
    {
        var startMonth = dtpStartMonth.Value.Month +"/" + "01"  + "/" + dtpStartMonth.Value.Year;
        var endMonth = dtpEndMonth.Value.Month + "/" + "01" + "/" + dtpEndMonth.Value.Year;
        // TODO: This line of code loads data into the 'DataSetEmployeeTurnover.DataTable1' table. You can move, or remove it, as needed.
        this.DataTable1TableAdapter.Fill(this.DataSetEmployeeTurnover.DataTable1,startMonth,endMonth);
        this.reportViewer1.RefreshReport();
    }

报告只显示一条记录,而DataTable有许多记录

如果你想在列表中填充所有的数据集记录,那么你必须在rdlc报告中使用tablix控件。

绑定RDLC报告代码:

ReportViewer1.ProcessingMode = ProcessingMode.Local 
Dim RDS As New ReportDataSource("DataSet1", atasetName.Tables(0))   
ReportViewer1.LocalReport.DataSources.Clear() 
ReportViewer1.LocalReport.DataSources.Add(RDS)
Me.ReportViewer1.RefreshReport()

我有同样的问题,它是通过这种方式解决的:以设计形式在报告上。使用报表查看器的RDLC选择文本框上的"Expression"并删除First函数

=First(Fields!coln_date.Value) ==>  =Fields!coln_date.Value

您可以使用Table或List来解决这个问题