locked
Issue while Integrating Microsoft.Reporting.WebForms class with SSRS reports System.InvalidCastException RRS feed

  • Question

  • User-1167068864 posted

    We are using Microsoft.Reporting.WebForms reportparameter[] class to send parameters to report viewer as in the code below .Here the RDL files is expecting datatype as Boolean\Date etc.

    Since the ReportParameter.ReportParameter accepts only string values  while rendering I am getting System.InvalidCastException.What is the workaround for this issue



     

    ReportParameter[] repParams = new ReportParameter[2];
                        if (Session["rptCurrentPage"].ToString() == "1")
                        {
                            repParams[0] = new ReportParameter("param_ParentRecordKey", Session["ID"].ToString());
                            repParams[1] = new ReportParameter("param_UserID", SessionHelper.UserProfile.ApplicationUserId.ToString());
                        }
                        else
                        {
                            repParams[0] = new ReportParameter("param_SubsidiaryAccountRecordSystemKey", Session["ID"].ToString());
                            repParams[1] = new ReportParameter("param_UserID", SessionHelper.UserProfile.ApplicationUserId.ToString());
                        }
                        ReportViewer1.ServerReport.SetParameters(repParams);
                        ReportViewer1.ServerReport.Refresh();

     

    Friday, May 29, 2015 8:40 AM

Answers

  • User1711366110 posted

    Since the ReportParameter.ReportParameter accepts only string values  while rendering I am getting System.InvalidCastException.What is the workaround for this issue

        According to this case, you can pass the strings value instead of Boolean values like  "1" for "true" , "0" for "false"

    Then in the Report Data pane, right-click the dataset, click Dataset Properties, and then click Parameters.

    • In the column Parameter Name, find the name of the query parameter. Parameter names are automatically populated based on the query.

    • In Parameter Value, click fx button then type in an expression that evaluates to the Boolean value to pass to the query parameter like below :
      =IIF(Parameters!yourReportParametername.value=true, "1", "0" ) 
    • Click OK
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 1, 2015 2:26 AM