我在VB2010上创建了一个报告(不是向导),我以编程方式使用数据集设置了数据源,我想在报告中添加一个过滤选项
原始代码: 此代码显示所有没有过滤的数据
Dim rptDataSource As ReportDataSource
With rptReportViewer.LocalReport
.ReportPath = "Reports\" & strReport & ".rdlc"
.DataSources.Clear()
End With
Select Case strReport
Case "rptProducts"
Dim ds As New dsProducts
Dim da As New dsProductsTableAdapters.ProductsTableAdapter
da.Fill(ds.Products)
'//use the same name as defined in the report Data Source Definition
rptDataSource = New ReportDataSource("ProductsDataSet", ds.Tables("Products"))
End Select
rptReportViewer.LocalReport.DataSources.Add(rptDataSource)
rptReportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
rptReportViewer.ZoomMode = ZoomMode.Percent
rptReportViewer.RefreshReport()
我做了一些谷歌搜索,我插入了一些代码
修改后的代码
Dim rptDataSource As ReportDataSource
**'this code inserted**
Dim FilterBrand As New ReportParameter("FilterBrand", txtfilter.Text)
With rptReportViewer.LocalReport
.ReportPath = "Reports\" & strReport & ".rdlc"
.DataSources.Clear()
End With
Select Case strReport
Case "rptProducts"
Dim ds As New dsProducts
Dim da As New dsProductsTableAdapters.ProductsTableAdapter
da.Fill(ds.Products)
'//use the same name as defined in the report Data Source Definition
rptDataSource = New ReportDataSource("ProductsDataSet", ds.Tables("Products"))
End Select
rptReportViewer.LocalReport.DataSources.Add(rptDataSource)
**'this code inserted**
rptReportViewer.LocalReport.SetParameters(New ReportParameter() {FilterBrand})
rptReportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
rptReportViewer.ZoomMode = ZoomMode.Percent
rptReportViewer.RefreshReport()
报告说在报告处理期间发生错误,有什么问题,如何以编程方式设置过滤?
由于