在 VB.Net 中手动在 Reportviewer 中加载 .rdlc 报告
Loading .rdlc report in Reportviewer manually in VB.Net
我需要 reportviewer 的认真帮助。
我看到了很多链接,尝试了很多代码,但找不到合适的解决方案。
请让我明白,解开我的疑惑。
在代码中完全混淆了哪个数据集 select 以及什么是 datasource.value 每次都会给我错误的东西...
我将展示我如何创建报告并尝试使其发挥作用的步骤。这是因为我在创建报告时可能犯了任何错误,你们可能会发现。
现在问题描述如下,
我有很多 .rdlc 报告我的项目。
我做的是
注意:包含表单名称的报表查看器是 Reports.vb
RDLC 报告为 Reports1.rdlc、Report2.rdlc、...
1) 创建报告,如添加 -> 新项目 -> 报告 -> 报告 -> Report1.rdlc
报告名称:Report1.rdlc
2) 然后我从这里添加数据集......
3) DataSet 属性打开,它甚至打开 DataSource 配置向导。
我 select 存储过程因为我想从我的存储过程中获取数据并按下完成。
这里的数据集名称是 BonnyDataSet
4) 之后,我 select 来自数据集属性的数据源...
现在,最后这里的可用数据集是什么……???
在 ReportViewer 中加载期间我必须考虑哪个数据集???
5) 现在,我通过添加数据集 1 中的数据列来组织该列,如下所示……
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
我得到如下错误:
BC30311 : Value of type 'ReportDataSource' cannot be converted to
'ReportDataSource'
我不知道这个错误。
我试过的另一个代码是
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 : Value of type 'LocalReport' cannot be converted to
'LocalReport'.
我也试了很多其他的但是不明白是什么问题。
我在创建 .rdlc 报告时做错了什么吗???
急需帮助。谢谢
您应该考虑这些注意事项:
你有一个编译时错误说:
BC30311 : Value of type 'ReportDataSource' cannot be converted to
'ReportDataSource'
所以您应该检查您是否使用正确的 ReportDataSource
引用并使用来自正确命名空间的 class。一个常见的问题是,当您在 Windows Forms 项目中添加 Microsoft.Reporting.WebForms.dll
作为引用并添加 Import Microsoft.Reporting.WebForms
命名空间时,您将收到此类异常。
修复后,您应该注意报告中的 DataSet
的名称应该与您在创建新的 ReportDataSource
时使用的名称相同。例如,如果 DataSet
的名称是 DataSet1
,您应该使用这样的代码:
Dim rds = New ReportDataSource("DataSet1", data)
要传递给报表的 data
应该与报表使用的结构相同。例如,它应该是 DataTable
:
的一个实例
TableAdapter1.Fill(Me.DataSet1, "Table1")
Dim rds = New ReportDataSource("DataSet1", Me.DataSet1.Table1)
设置您使用的报告时,请使用正确的资源名称。例如,如果您的项目根目录中有一个 Report1
,并且项目的默认命名空间是 YourProjectNamespace
,那么资源名称将是:
ReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectNamespace.Report1.rdlc"
当您的报告位于文件夹中时,文件夹名称也会添加到其资源名称中。
我需要 reportviewer 的认真帮助。
我看到了很多链接,尝试了很多代码,但找不到合适的解决方案。
请让我明白,解开我的疑惑。
在代码中完全混淆了哪个数据集 select 以及什么是 datasource.value 每次都会给我错误的东西...
我将展示我如何创建报告并尝试使其发挥作用的步骤。这是因为我在创建报告时可能犯了任何错误,你们可能会发现。
现在问题描述如下,
我有很多 .rdlc 报告我的项目。
我做的是
注意:包含表单名称的报表查看器是 Reports.vb
RDLC 报告为 Reports1.rdlc、Report2.rdlc、...
1) 创建报告,如添加 -> 新项目 -> 报告 -> 报告 -> Report1.rdlc
报告名称:Report1.rdlc
2) 然后我从这里添加数据集......
3) DataSet 属性打开,它甚至打开 DataSource 配置向导。
我 select 存储过程因为我想从我的存储过程中获取数据并按下完成。
这里的数据集名称是 BonnyDataSet
4) 之后,我 select 来自数据集属性的数据源...
现在,最后这里的可用数据集是什么……???
在 ReportViewer 中加载期间我必须考虑哪个数据集???
5) 现在,我通过添加数据集 1 中的数据列来组织该列,如下所示……
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
我得到如下错误:
BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'
我不知道这个错误。
我试过的另一个代码是 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 : Value of type 'LocalReport' cannot be converted to 'LocalReport'.
我也试了很多其他的但是不明白是什么问题。
我在创建 .rdlc 报告时做错了什么吗???
急需帮助。谢谢
您应该考虑这些注意事项:
你有一个编译时错误说:
BC30311 : Value of type 'ReportDataSource' cannot be converted to 'ReportDataSource'
所以您应该检查您是否使用正确的
ReportDataSource
引用并使用来自正确命名空间的 class。一个常见的问题是,当您在 Windows Forms 项目中添加Microsoft.Reporting.WebForms.dll
作为引用并添加Import Microsoft.Reporting.WebForms
命名空间时,您将收到此类异常。修复后,您应该注意报告中的
DataSet
的名称应该与您在创建新的ReportDataSource
时使用的名称相同。例如,如果DataSet
的名称是DataSet1
,您应该使用这样的代码:Dim rds = New ReportDataSource("DataSet1", data)
要传递给报表的
的一个实例data
应该与报表使用的结构相同。例如,它应该是DataTable
:TableAdapter1.Fill(Me.DataSet1, "Table1") Dim rds = New ReportDataSource("DataSet1", Me.DataSet1.Table1)
设置您使用的报告时,请使用正确的资源名称。例如,如果您的项目根目录中有一个
Report1
,并且项目的默认命名空间是YourProjectNamespace
,那么资源名称将是:ReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectNamespace.Report1.rdlc"
当您的报告位于文件夹中时,文件夹名称也会添加到其资源名称中。