locked
Hopw to pass parameter to rdlc Report in ASP.Net? RRS feed

  • Question

  • User86684591 posted

    Greetings,

    I`m developing an ASP.NET web application using VB code in VS 2013. I have designed rdlc report "Report1" and locate a Report Viewer inside a page "ReportViewer.aspx".

    I've created a dataset and created a table "Table1" inside it. Then I configured the Report1 datasource to get data from that Table1. The report is running great; however, when I passed a parameter to it, an error is generated at runtime:

    "An error occurred during local report processing. The definition of the report 'Main Report' is invalid"

    Note the following details:

    • VS 2013 project .Net Framework: 4.5
    • References: Microsoft.ReportViewer.Common & Microsoft.ReportViewer.WebForm runtime version is v2.0.50727

    Hereafter is my code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                Dim dt As DataTable
                dt = CType(Session("table"), DataTable)
                'Dim ds As DataSet
                'ds = CType(Session("dataset"), DataSet)
                Dim rptname As String
                rptname = Session("rptname")
                Dim title As String
                title = Session("title")
                Dim color As Integer
                color = Session("color")
                Dim Param() As ReportParameter = {New ReportParameter("paramTitle", title)}          
                If Not IsPostBack Then
                    rptViewer.ProcessingMode = ProcessingMode.Local
                    rptViewer.LocalReport.ReportPath = Server.MapPath("~/Reports/" & rptname)
                    Dim datasource As New ReportDataSource("ds", dt)
                    rptViewer.LocalReport.DataSources.Clear()
                    rptViewer.LocalReport.DataSources.Add(datasource)
                    rptViewer.LocalReport.SetParameters(Param(0))       
                    rptViewer.LocalReport.Refresh()
                End If
            Catch ex As Exception
                Response.Write(ex.Message)
            End Try
        End Sub

    Please advise what I`m doing wrong, and communicate your workaround to resolve this issue.

    Thanks,

    Monday, April 27, 2015 8:57 AM

All replies

  • User-1392847221 posted

    I hope below link may help you.

    http://cybarlab.com/pass-parameter-in-rdlc-report

    Monday, April 27, 2015 9:10 AM
  • User86684591 posted

    I`m afraid that the solution presented in that web page is not working in my case.

    I wonder if there is something related to the references run-time version which is v2.0 and not v4.0...however when I remove the parameter from the report, everything works fine.

    So, it is weird.

    Please Help!!

    Monday, April 27, 2015 9:23 AM
  • User1711366110 posted


    I've created a dataset and created a table "Table1" inside it. Then I configured the Report1 datasource to get data from that Table1. The report is running great; however, when I passed a parameter to it, an error is generated at runtime:
    "An error occurred during local report processing. The definition of the report 'Main Report' is invalid"

      As per this case, you can try the following code :

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                Dim dt As DataTable = CType(Session("table"), DataTable)
    
    'Dim ds As DataSet = CType(Session("dataset"), DataSet)
    Dim rptname As String = Session("rptname").ToString()
    Dim title As String = Session("title").ToString()
    Dim color As Integer = Convet.ToInt32(Session("color").ToString())
    Dim Param As ReportParameter = New ReportParameter(3)
    If Not IsPostBack Then rptViewer.ProcessingMode = ProcessingMode.Local rptViewer.LocalReport.ReportPath = Server.MapPath("~/Reports/") Dim datasource As New ReportDataSource("ds", dt) rptViewer.LocalReport.DataSources.Clear() rptViewer.LocalReport.DataSources.Add(datasource) Param(0) =new ReportParameter("param_rptname", rptname); Param(1) =new ReportParameter("param_title",title); Param(2) =new ReportParameter("param_color",color); rptViewer.LocalReport.SetParameters(Param) rptViewer.LocalReport.Refresh() End If Catch ex As Exception Response.Write(ex.Message) End Try End Sub

    --
    with regards,
    Edwin

    Tuesday, April 28, 2015 1:51 AM
  • User86684591 posted

    Thanks Edwin for your reply,

    I replaced the code with your suggested one; however, The following line contains syntax error:

    Dim Param As ReportParameter = New ReportParameter(3)

    So I replace it with my code: 

    Dim Param() As ReportParameter = {New ReportParameter("paramTitle", title)}

    But after this the same error still generated.

    Please Support, 

    Tuesday, April 28, 2015 2:48 AM
  • User1711366110 posted


    I replaced the code with your suggested one; however, The following line contains syntax error:

    Dim Param As ReportParameter = New ReportParameter(3)


       As per this case, you can try like below :

    Dim Param() As ReportParameter = New ReportParameter(3) {}
    Tuesday, April 28, 2015 10:13 PM
  • User86684591 posted

    Thanks Edwin,

    I tried the updated line code you submitted, and the syntax error has gone.

    However the following error still persist:

    An error occurred during local report processing.
    The definition of the report 'A:\Development\Web App\WebTIP\WebTIP\rptApprCostDiv.rdlc' is invalid.
    An unexpected error occurred while compiling expressions. Native compiler return value: ‘[BC2001] file 'C:\Windows\TEMP\cr0sb0xb.0.vb' could 
    not be found’.

    For more info, below are the environment configuration parameters of my project:

    1. The Project is created in MS VS 2013 as ASP.NET Web Form
    2. Target Framework: .Net Framework 4.5
    3. Application Type: Class Library
    4. Relevant Report References: 
      • Microsoft.ReportViewer.Common: Version: 11.0.0.0  & Runtime Version: v2.0.50727
      • Microsoft.ReportViewer.WebForms: Version: 11.0.0.0  & Runtime Version: v2.0.50727

    I hope these details may give you extra knowledge about what is happening over here, and though you may provide me with your value support.

    Please Help!

    dgharib...

    Thursday, April 30, 2015 3:20 AM
  • User-1078840699 posted

    1) Open Report viewer (RDLC Report).
    2) Select Report(Menu) ----->Report Parameters.


    3) Report Parameter window will be open.


    4)Select Add Button to Pass New Parameters.


    5)Enter Name And Prompt As Same Name.


    6)After Enter Datatype of Parameters.


    7)After Open RDLC Report, Select Fields To Pass Parameters.


    8)Right Click on Fields and Add Expression :


         =Parameters!<Parameter Name>.Value

    9)  Add Parameters code Report viewer.aspx.cs  Page.


      ReportParameter rp = new ReportParameter("<Parameter Name", this.<Textbox ID>.Text);

      this.ReportViewer.LocalReport.SetParameters(new ReportParameter[] { rp });


      ReportViewer.LocalReport.Refresh();

    Do check this link

    Monday, May 4, 2015 3:27 PM
  • User86684591 posted

    Thanks JohnBert for the consideration,

    However I have been trying all the day to find out how to apply the steps in your post and I did not succeed. My question is where to select the Report Parameters from Report Menu. 

    Please help in how to apply steps 1-6 in your proposed solution!!

    Furthermore, I have tried the scenario found in your submitted url: http://gopika-lasitha.blogspot.com/2012/06/passing-parameter-value-for-rdlc-report.html and it was successful.

    Thus I think the problem is not very related to the version of the Report References I added in step 4 in my previous post...

    What we can do further, please help!.

    Tuesday, May 5, 2015 8:01 AM