在 VB.Net 中手动在 Reportviewer 中加载 .rdlc 报告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40056855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Loading .rdlc report in Reportviewer manually in VB.Net
提问by bonny
I need a serious help in reportviewer.
I seen a lot links, tried a lot codes every way but cannot find a proper solution.
Please make me understand and clear my doubts even.
Totally confused which dataset to select during code and what is datasource.value thing which gives me error everytime...
我需要在 reportviewer 中的认真帮助。
我看到了很多链接,尝试了很多代码,但找不到合适的解决方案。甚至请让我理解并消除我的疑虑。
完全混淆了在代码期间选择哪个数据集以及什么是 datasource.value 每次都会给我错误的东西......
I am showing the steps how I created the report and trying to make it work. This because I might have done any mistake in creating the reports and you people may catch it.
我正在展示我如何创建报告并尝试使其工作的步骤。这是因为我可能在创建报告时犯了任何错误,你们可能会发现它。
Now the problem is described below,
I have many .rdlc reporting my project.
What I done is
现在问题描述如下,我有很多 .rdlc 报告我的项目。我所做的是
Note : Reportviewer containing form name is Reports.vb
RDLC reports are Reports1.rdlc,Report2.rdlc,...
注意:包含表单名称的 Reportviewer 是Reports.vb
RDLC 报告是 Reports1.rdlc,Report2.rdlc,...
1) Created Report like Add -> New Item -> Reporting -> Report -> Report1.rdlc
Report Name: Report1.rdlc
1)创建报告,如添加 -> 新项目 -> 报告 -> 报告 -> Report1.rdlc
报告名称:Report1.rdlc
2) Then I add dataset from here like this … 
3) DataSet properties opens, it even opens DataSource configuration Wizard.
I select stored procedures because I want to fetch data from my stored procedures and pressed Finish.
Here DataSet Name is BonnyDataSet
3) DataSet 属性打开,它甚至打开 DataSource 配置向导。我选择存储过程是因为我想从我的存储过程中获取数据并按完成。
这里的数据集名称是BonnyDataSet
4) After that, I select data source from dataset properties…
Now what is this Available datasets here in the last…???
And which dataset I have to consider during loading in ReportViewer???
4) 之后,我从数据集属性中选择数据源......
现在最后一个可用的数据集是什么......???
在 ReportViewer 中加载时我必须考虑哪个数据集???
5) Now I organised the column by adding the data columns from dataset1 shown below…
5)现在我通过添加数据集1中的数据列来组织列,如下所示......
6) Now I added Reportviewer in form Reports.vb and tried a lot of codes….
Showing some of them here.
6) 现在我以 Reports.vb 的形式添加了 Reportviewer 并尝试了很多代码......
在这里展示其中的一些。
Private Sub Reports_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
'Select Case PubRepVar
'Case "AccMast"
Dim data As New BonnyDataSet
Dim rds = New ReportDataSource("BonnyDataSet", data)
ReportViewer.LocalReport.DataSources.Clear()
ReportViewer.LocalReport.DataSources.Add(rds) ‘------error here
ReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectNamespace.Report1.rdlc"
ReportViewer.RefreshReport()
'End Select
Catch ex As Exception
MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
I get the error as following:
我收到如下错误:
BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'
BC30311:“ReportDataSource”类型的值无法转换为“ReportDataSource”
I have no Idea on this error.
我对这个错误一无所知。
Another code I tried is ReportViewer.ProcessingMode = ProcessingMode.Local
我试过的另一个代码是 ReportViewer.ProcessingMode = ProcessingMode.Local
Dim localReport As LocalReport
localReport = ReportViewer.LocalReport ‘-------error here
localReport.ReportEmbeddedResource =
"ReportViewerIntro.Report1.rdlc"
Dim dataset As New DataSet("BonnyDataSet")
Here error shows like :
这里的错误显示如下:
BC30311 : Value of type 'LocalReport' cannot be converted to 'LocalReport'.
BC30311:“LocalReport”类型的值无法转换为“LocalReport”。
And I tried many other but can't understand what the problem is.
Am I doing something wrong during the creation of .rdlc reports???
我尝试了很多其他但不明白问题是什么。我在创建 .rdlc 报告时做错了什么???
Needed help eagerly. Thanx
急切需要帮助。谢谢
采纳答案by Reza Aghaei
You should consider these notes:
您应该考虑以下注意事项:
You have a compoile-time error saying:
BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'
So you should check if you are using correct reference for
ReportDataSourceand using the class from correct namespace. A common problem is when you addedMicrosoft.Reporting.WebForms.dllas reference in a Windows Forms Project and addedImport Microsoft.Reporting.WebFormsnamespace, so you will receive such exception.After fixing that, you should pay attention the name of
DataSetin your report should be the same name which you use when creating a newReportDataSource. For example if the name ofDataSetisDataSet1, you should use such code:Dim rds = New ReportDataSource("DataSet1", data)The
datawhich you want to pass to the report should be in the same structure which is used by report. For example, it should be an instance of aDataTable:TableAdapter1.Fill(Me.DataSet1, "Table1") Dim rds = New ReportDataSource("DataSet1", Me.DataSet1.Table1)When setting which report you are using, use correct resource name. For example if you have a
Report1in root of your project, and default namspace of your project isYourProjectNamespacethen the resource name would be:ReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectNamespace.Report1.rdlc"When your report is in a folder, the folder name also will be added to its resource name.
你有一个编译时错误说:
BC30311:“ReportDataSource”类型的值无法转换为“ReportDataSource”
所以你应该检查你是否使用了正确的引用
ReportDataSource并使用了来自正确命名空间的类。一个常见的问题是,当您Microsoft.Reporting.WebForms.dll在 Windows 窗体项目中添加为引用并添加Import Microsoft.Reporting.WebForms命名空间时,您会收到此类异常。修复后,您应该注意
DataSet报告中的名称应与您在创建新ReportDataSource. 例如,如果名称DataSet为DataSet1,则应使用以下代码:Dim rds = New ReportDataSource("DataSet1", data)将
data要传递给报告应当在其中使用的报告相同的结构。例如,它应该是 a 的一个实例DataTable:TableAdapter1.Fill(Me.DataSet1, "Table1") Dim rds = New ReportDataSource("DataSet1", Me.DataSet1.Table1)在设置您使用的报告时,请使用正确的资源名称。例如,如果您
Report1在项目的根目录中有一个,并且项目的默认 namspace 是YourProjectNamespace那么资源名称将是:ReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectNamespace.Report1.rdlc"当您的报表位于文件夹中时,文件夹名称也将添加到其资源名称中。

