[RESOLVED] Cannot pass parameters to report
I have used this method many times with success, but all of a sudden its not working.
I have a report with two parameters.
I am trying to pass these two with the following code :
Code:
Me.PenalisasieTableAdapter.Fill(Me.LutzvilleDataSet.penalisasie)
Dim param1 As New ReportParameter("ReportParameterALIASNAAM", KiesVorm.CmbAliasnaam4.SelectedItem.ToString())
Dim param2 As New ReportParameter("ReportParameterPENALISASIE", KiesVorm.GepenaliseerComboBox.SelectedItem.ToString())
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {param1, param2})
Me.ReportViewer1.Show()
Me.ReportViewer1.RefreshReport()
I get the following error : : 'Unable to cast object of type 'Microsoft.Reporting.WebForms.ReportParameter[]' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'.'
I have searched in vain to get a solution. Please can someone help me, before I go mad.
Regards
Re: Cannot pass parameters to report
Does anyone know if it it possible to filter a report's dataset with SQL rather than using the parameters in the report?
Re: Cannot pass parameters to report
I don't know about that, but I have spotted an issue in the error message that is easy to overlook:
Microsoft.Reporting.WebForms.ReportParameter
Microsoft.Reporting.WinForms.ReportParameter
It seems that somehow different assumptions are being made about whether you want the WebForms or WinForms variant... so specifying should solve it, eg:
Code:
Dim param1 As New Microsoft.Reporting.WinForms.ReportParameter("ReportParameterALIASNAAM", KiesVorm.CmbAliasnaam4.SelectedItem.ToString())
Dim param2 As New Microsoft.Reporting.WinForms.ReportParameter("ReportParameterPENALISASIE", KiesVorm.GepenaliseerComboBox.SelectedItem.ToString())
Me.ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WinForms.ReportParameter() {param1, param2})
(I've assumed WinForms, so change that to WebForms if apt)
Re: Cannot pass parameters to report
Good catch there... I'd be more inclined to believe the wrong namespace was imported... changing that might also fix the problem.
-tg
Re: Cannot pass parameters to report
Thank you for spotting that Si.
It is as techgnome below suggested - I've imported the wrong namespace.
Regards
Re: Cannot pass parameters to report
Thank you techgnome
I have indeed imported the wrong namespace:
Code:
''Imports Microsoft.Reporting.WebForms
Imports Microsoft.Reporting.WinForms
Regards
Re: [RESOLVED] Cannot pass parameters to report
Hi,I am Nany Swip
I have faced problems many times before which are very difficult for you to solve now. I have tried many times in the past with some code but could not find the exact solution if you know please tell me.