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

时间:2014-08-20 02:22:41

标签: c# .net winforms reportviewer rdlc

我在我的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();
    }

2 个答案:

答案 0 :(得分:1)

如果要填充列表中的所有数据集记录,则必须在rdlc报告中使用tablix Control。

绑定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()

答案 1 :(得分:0)

我遇到了同样的问题,并以这种方式解决了: 使用报表查看器在report.rdlc上以设计形式 在文本框中选择“表达式”,然后删除“第一个功能”

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