在VB.Net中手动在Reportviewer中加载.rdlc报告 [英] Loading .rdlc report in Reportviewer manually in VB.Net
问题描述
我在reportviewer中需要认真的帮助。
我看到了很多链接,尝试了很多代码,但找不到合适的解决方案。
请甚至让我理解并清除我的疑问。
完全混淆了在代码期间选择哪个数据集以及什么是datasource.value东西,每次都会给我错误......
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...
我正在显示创建报告并尝试使其工作的步骤。这是因为我在创建报告时可能犯了任何错误,并且您可能会发现它。
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.
现在问题在下面描述,
我有很多.rdlc报告我的项目。
我要做的是
Now the problem is described below,
I have many .rdlc reporting my project.
What I done is
注意:包含表单名称的Reportviewer是 Reports.vb
RDLC报告是Reports1.rdlc,Report2.rdlc,...
Note : Reportviewer containing form name is Reports.vb
RDLC reports are Reports1.rdlc,Report2.rdlc,...
1)创建的报告,例如添加->新项目->报告->报告-> Report1.rdlc
报告名称:Report1.rdlc
1) Created Report like Add -> New Item -> Reporting -> Report -> Report1.rdlc
Report Name: Report1.rdlc
2)然后,我从此处添加数据集,例如…
< a href = https://i.stack.imgur.com/0USsU.png rel = noreferrer>
2) Then I add dataset from here like this …
3)DataSet属性打开,它甚至会打开DataSource配置向导。
我选择存储过程是因为我想从存储过程中获取数据并按Finish。
此处的数据集名称为 BonnyDataSet
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
4)之后,我从数据集属性中选择数据源…
现在最后一个可用的数据集是什么?
还有在ReportViewer加载期间必须考虑的数据集???
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???
5)现在,我组织了通过添加如下所示的dataset1中的数据列来添加该列…
5) Now I organised the column by adding the data columns from dataset1 shown below…
6)现在,我在Reports.vb表单中添加了Reportviewer,并尝试了很多代码……。
在此处显示其中的一些。
6) Now I added Reportviewer in form Reports.vb and tried a lot of codes….
Showing some of them here.
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
我收到如下错误:
BC30311:类型'ReportD的值ataSource无法转换为
'ReportDataSource'
BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'
我不知道此错误。
我尝试的另一个代码是
ReportViewer.ProcessingMode = ProcessingMode.Local
Another code I tried is ReportViewer.ProcessingMode = ProcessingMode.Local
Dim localReport As LocalReport
localReport = ReportViewer.LocalReport ‘-------error here
localReport.ReportEmbeddedResource =
"ReportViewerIntro.Report1.rdlc"
Dim dataset As New DataSet("BonnyDataSet")
此处错误显示如下:
BC30311:类型'LocalReport'的值不能转换为
'LocalReport'。
BC30311 : Value of type 'LocalReport' cannot be converted to 'LocalReport'.
我尝试了许多其他方法,但不明白是什么问题。
在创建.rdlc报告期间我做错什么了吗?
And I tried many other but can’t understand what the problem is.
Am I doing something wrong during the creation of .rdlc reports???
迫切需要帮助。谢谢
推荐答案
您应考虑以下注意事项:
You should consider these notes:
-
您有一个combiile-time错误,说:
You have a compoile-time error saying:
BC30311: ReportDataSource类型的值无法转换为
'ReportDataSource'
BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'
因此,您应该检查 ReportDataSource是否使用正确的引用
并使用正确名称空间中的类。一个常见的问题是在Windows Forms项目中添加 Microsoft.Reporting.WebForms.dll
作为引用并添加 Import Microsoft.Reporting.WebForms
名称空间,因此您将收到此类异常。
So you should check if you are using correct reference for ReportDataSource
and using the class from correct namespace. A common problem is when you added Microsoft.Reporting.WebForms.dll
as reference in a Windows Forms Project and added Import Microsoft.Reporting.WebForms
namespace, so you will receive such exception.
修复该问题后,应注意 DataSet的名称。报表中的
应该与创建新的 ReportDataSource
时使用的名称相同。例如,如果 DataSet
的名称为 DataSet1
,则应使用以下代码:
After fixing that, you should pay attention the name of DataSet
in your report should be the same name which you use when creating a new ReportDataSource
. For example if the name of DataSet
is DataSet1
, you should use such code:
Dim rds = New ReportDataSource("DataSet1", data)
要传递给报表的数据
应该与报表使用的结构相同。例如,它应该是 DataTable
的实例:
The data
which 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 a DataTable
:
TableAdapter1.Fill(Me.DataSet1, "Table1")
Dim rds = New ReportDataSource("DataSet1", Me.DataSet1.Table1)
设置要使用的报告时,请使用正确的资源名称。例如,如果您在项目的根目录中有 Report1
,并且项目的默认命名空间是 YourProjectNamespace
,则资源名称为:
When setting which report you are using, use correct resource name. For example if you have a Report1
in root of your project, and default namspace of your project is YourProjectNamespace
then 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.
这篇关于在VB.Net中手动在Reportviewer中加载.rdlc报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!