那么,如何在ReportViewer中动态呈现rdlc? [英] So, how DO you render an rdlc dynamically in a ReportViewer??
问题描述
我读过很多文章,看过很多关于如何使用rdlc和reportviewer动态呈现报告的例子,其中没有一个能够成功呈现报告,但只是很多混乱。我希望有人能为我解决问题并告诉我如何正确地做到这一点。
我的报告(SalesReport) .rdlc)有两个字符串参数,Quarter和AgencyType。这是我正在使用的代码:
My report (SalesReport.rdlc) has two string parameters, Quarter and AgencyType. Here's the code I'm using:
使用 ReportViewer1
With ReportViewer1
.Visible = 真
.Visible = True
.Reset()
.LocalReport.ReportPath = " MMQ\Reports\QM按日期汇总数据Range.rdlc"
.LocalReport.ReportPath = "MMQ\Reports\QM Aggregate Data by Date Range.rdlc"
Dim rdsReport As 新 ReportDataSource
Dim rdsReport As New ReportDataSource
使用 rdsReport
With rdsReport
.Name = " QMAggDataRptDa taSource"
.Name = "QMAggDataRptDataSource"
.Value = dtReport '之前创建的代码
.Value = dtReport 'Created earlier in the code
结束 使用
End With
.LocalReport.DataSources.Clear ()
.LocalReport.DataSources.Clear()
.LocalReport.DataSources.Add(rdsReport)
.LocalReport.DataSources.Add(rdsReport)
'所有RptParam_变量都已在代码中设置
'All RptParam_ variables have been set earlier in the code
Dim prmQrTitle As New ReportParameter( " Quarter" ,Rp tParam_Qarter)
Dim prmQrTitle As New ReportParameter("Quarter", RptParam_Qarter)
Dim prmAgencyType As New ReportParameter( " AgencyType" ,RptParam_AgencyType)
Dim prmAgencyType As New ReportParameter("AgencyType", RptParam_AgencyType)
Dim parameters() As ReportParameter = {prmQuarter,prmAgencyType}
Dim parameters() As ReportParameter = {prmQuarter, prmAgencyType}
.LocalReport.SetParameters(parameters)
.LocalReport.SetParameters(parameters)
.DataBind()
.DataBind()
.LocalReport.Refresh()
.LocalReport.Refresh()
结束 使用
End With
以下是我遇到的问题:
如果我使用Smar tTag的ReportViewer创建数据集,最终创建一个TableAdapter和一个ObjectDataSource。然后,我将结果DataTable分配给报表中表的DataSetName属性。当我运行它时,它会通过代码而没有错误,但是应该呈现报告(ReportViewer所在的位置),我收到此错误:
If I use the SmartTag of the ReportViewer to create a dataset, it ends up creating a TableAdapter and an ObjectDataSource. I then assign the resulting DataTable to the DataSetName property of the table in the report. When I run this, it goes through the code without an error, but where the report should be rendered (where the ReportViewer is), I get this error:
尚未为数据源'SalesReport_SalesReportTable'提供数据源实例
如果我重置(删除值)DataSetName属性,我得到相同的错误。如果我然后在文本错误中打开rdlc并删除< DataSets>元素及其所有内容,我在complie上得到这个错误:
If I reset (delete the value of) the DataSetName property, I get the same error. If I then open the rdlc in a text error and delete the <DataSets> element and all its contents, I get this error at complie:
错误1表'table2'在报告正文中,但是报告没有数据集。没有数据集的报告中不允许使用数据区域。
Error 1 The table ‘table2’ is in the report body but the report has no data set. Data regions are not allowed in reports without datasets.
所以,我很困惑。如果我要分配DataTable动态(在运行时),是否仍需要将报表的DataSetName属性分配给数据表?如果我分配一个DataTable,我怎么能摆脱这种情况,如果我不这样做,我会收到错误。我如何设置,以便我可以在ReportViewer和DataTable中将报告分配给LocalReport代码?
So, I'm very confused. If I am going to assign a DataTable dynamicall (at runtime), do I still need to have the DataSetName property of the report table assigned to a datatable? How can I get away from this situation in which I get errors if I assign a DataTable and I get errors if I don't. How DO I set things up so that I can assign a report to a ReportViewer and a DataTable to the LocalReport in code?
非常感谢你非常适合您的帮助。
Thank you very much for your help.
有人可以告诉我如何正确设置,以便我可以动态地将报告设置到reportviewer并动态地将DataTable分配给报告吗?
Can someone please tell me how to correctly set things up so that I can dynamically set a report to the reportviewer and dynamically assign a DataTable to the report?
推荐答案
您好,
在LocalReport上添加DataSource时,LocalReport使用类型名称指定DataSource名称,用'_'替换点。
When you add a DataSource on a LocalReport, LocalReport appoints a DataSource name with the name of the type, replacing points with '_'.
示例:
如果您有一个objet NamespaceToto.Toto,DataSource的名称将是" NamespaceToto_Toto"。
If you have an objet NamespaceToto.Toto, the name of DataSource will be "NamespaceToto_Toto".
必须创建一个具有相同名称的DataSource:
Must be created a DataSource with the same name :
这篇关于那么,如何在ReportViewer中动态呈现rdlc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!