locked
Passing Parameters to a Local Report (.rdlc) RRS feed

  • Question

  • User-2100942636 posted

    I'm having a heck of a time figuring this out. I have a local report in my Website that I need to pass 4 control parameters to. Here is the ReportViewer code.

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
         Height="700px" Width="100%">
         <LocalReport ReportPath="reports\Report.rdlc">
         <DataSources>
             <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="Students_sp_StoredProcedure" />
         </DataSources>
         </LocalReport>
    </rsweb:ReportViewer>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
         TypeName="StudentsTableAdapters.sp_StoredProcedureTableAdapter" OldValuesParameterFormatString="{0}">
         <SelectParameters>
              <asp:ControlParameter ControlID="txtParam1" Name="PARAM_1" PropertyName="Text" Type="String" />
              <asp:ControlParameter ControlID="txtParam2" Name="PARAM_2" PropertyName="Text" Type="String" />
              <asp:ControlParameter ControlID="txtParam3" Name="PARAM_3" PropertyName="Text" Type="String" />
              <asp:ControlParameter ControlID="txtParam4" Name="PARAM_4" PropertyName="Text" Type="String" />         
         </SelectParameters>   
    </asp:ObjectDataSource>

    I have a DataSet (.xsd) defined that uses a stored procedure that contains all these parameters and I added all the parameters to the report via the Report menu in Visual Studio 2005.

    When I access the .aspx page that has the ReportViewer on it, I get the following error.

    The 'Withdrawn' parameter is missing a value

    If I assign default values for the report parameters via the Report menu in Visual Studio 2005, I get the following error.

  • ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetData' that has parameters: PARAM_1, PARAM_2, PARAM_3 PARAM_4.
  • Can somebody please point me in the right direction?

    Thanks in advance for your help.

     

Friday, March 28, 2008 2:46 PM

Answers

  • User1485238302 posted

    That is the dataset that you have configured to work with your report. I don't remember which menu is that, but its either Report menu or DataSources menu at the top of your report page where you can check the name. 

    <rsweb:ReportViewer ID="ReportViewer2" runat="server" 
    BackColor="Desktop" BorderColor="Gray" 
    Style="color: white; overflow: visible; border-top-width: thin; border-left-width: thin; border-bottom-width: thin; border-collapse: separate; border-right-width: thin;" Width="1000px" LinkActiveColor="White" LinkActiveHoverColor="255, 192, 128" LinkDisabledColor="224, 224, 224" InternalBorderStyle="None" Font-Names="Verdana;color:orange" Font-Size="8pt" 
    ShowExportControls="False" BorderStyle="None" BorderWidth="1px" 
    Height="400px" SizeToReportContent="True" >
    <LocalReport ReportPath="">
       <DataSources>
           <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1_MaintenanceDS" />
        </DataSources>
      </LocalReport>
    </rsweb:ReportViewer>
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 31, 2008 10:57 AM

All replies

  • User1850922970 posted

     What I know is, You cannot pass parameters when you run on local mode. The reason is given in this website.

     

    Q: Why doesn't the ReportViewer control support parameter prompting in local mode? <o:p></o:p>

    A: The ReportViewer control does not prompt for parameters when in local mode. It prompts for parameters when it is connected to a Report Server. <o:p></o:p>

    In local mode it does not make sense for ReportViewer to prompt for parameters. The rationale is as follows: The most common use of report parameters is to pass to queries as values of query parameters. But unlike the Report Server, the ReportViewer control does not execute queries itself. Rather, queries are executed by the host application, and the result is passed to the ReportViewer control. So the ReportViewer control does not have the opportunity to set query parameters. Applications should take advantage of the parameterization features of Visual Studio data wizards instead<o:p></o:p>

    http://www.gotreportviewer.com/<o:p></o:p>

    HTH

    Thanks, 

    Friday, March 28, 2008 6:47 PM
  • User-2100942636 posted

     Thanks for the reply. Does that mean I have to pass the parameters into the DataSet (.xsd) itself?

    Monday, March 31, 2008 9:26 AM
  • User1485238302 posted

    You can pass parameters to the report in local mode. If just won't prompt for the parameters as it does in server reports, for the reason stated above. This is how I add add parameters to the report: 

    public void FindBas()
    {
        // Set the processing mode for the ReportViewer to Local
        ReportViewer2.ProcessingMode = ProcessingMode.Local;
        LocalReport rep = ReportViewer2.LocalReport;
        rep.ReportPath = "Report2.rdlc";
        DataSet ds = GetSalesDataBas();
        // Create a report data source for the sales order data
        ReportDataSource dsMaintenanceDS = new ReportDataSource();
        dsMaintenanceDS.Name = "DataSet1_MaintenanceDS";
        dsMaintenanceDS.Value = ds.Tables["MaintenanceDS"];
        rep.DataSources.Clear();
    
        string[] _p1 = new string[] { param1, DropDownList25.SelectedValue };
        string[] _p2 = new string[] { param2, DropDownList26.SelectedValue };
        string[] _p3 = new string[] { param3, DropDownList27.SelectedValue };
        string[] _p4 = new string[] { param4, DropDownList28.SelectedValue };
    
        ReportParameter p1 = new ReportParameter("param1", _p1);
        ReportParameter p2 = new ReportParameter("param2", _p2);
        ReportParameter p3 = new ReportParameter("param3", _p3);
        ReportParameter p4 = new ReportParameter("param4", _p4);
          
        this.ReportViewer2.LocalReport.SetParameters(new ReportParameter[] {p1, p2, p3, p4});
    
        rep.DataSources.Add(dsMaintenanceDS);
        rep.Refresh();
    
    }
     
    Monday, March 31, 2008 9:40 AM
  • User-2100942636 posted

    Thanks for the reply. I'm still getting an error. Is DataSet1_MaintenanceDS the name of your typed DataSet? Also, what does the ReportViewer code look like on the .aspx page?

    Thanks again, I feel like I'm getting close.

    Monday, March 31, 2008 10:42 AM
  • User1485238302 posted

    That is the dataset that you have configured to work with your report. I don't remember which menu is that, but its either Report menu or DataSources menu at the top of your report page where you can check the name. 

    <rsweb:ReportViewer ID="ReportViewer2" runat="server" 
    BackColor="Desktop" BorderColor="Gray" 
    Style="color: white; overflow: visible; border-top-width: thin; border-left-width: thin; border-bottom-width: thin; border-collapse: separate; border-right-width: thin;" Width="1000px" LinkActiveColor="White" LinkActiveHoverColor="255, 192, 128" LinkDisabledColor="224, 224, 224" InternalBorderStyle="None" Font-Names="Verdana;color:orange" Font-Size="8pt" 
    ShowExportControls="False" BorderStyle="None" BorderWidth="1px" 
    Height="400px" SizeToReportContent="True" >
    <LocalReport ReportPath="">
       <DataSources>
           <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1_MaintenanceDS" />
        </DataSources>
      </LocalReport>
    </rsweb:ReportViewer>
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 31, 2008 10:57 AM
  • User-2100942636 posted

     Thanks for all your help. I finally got it to work. I'm just starting to get my feet wet with Reporting Services, could you recommend a good book on the subject?

    Thanks again. 

    Monday, March 31, 2008 11:14 AM
  • User1485238302 posted

    I don't think there is any book for Local Reports. If there are, then I am not aware of them. I learned everything from online resources like www.gotreportviewer.com, MSDN, people posting their own solutions etc.

    Monday, March 31, 2008 11:16 AM
  • User563557587 posted

    hi,thanks for providing good method, please say about what is param1

     string[] _p1 = new string[] { param1, DropDownList25.SelectedValue };
    pls reply   to harikrishna@v2k.in

    Wednesday, February 11, 2009 2:12 AM
  • User1485238302 posted

     

    hi,thanks for providing good method, please say about what is param1

     string[] _p1 = new string[] { param1, DropDownList25.SelectedValue };
    pls reply   to harikrishna@v2k.in

    Ignore these. Basically, I am sending values to multivalue parameters.

    So it would look like this:

    string[] _p1 = new string[] { DropDownList1.SelectedValue.Replace("_", " "), DropDownList1.SelectedValue };

    Here is how one of the fields look like in the designer: 

    <Field Name="Part_Number">
     <rd:TypeName>System.String</rd:TypeName>
       <DataField>Part Number</DataField>
    </Field>
     
    If you notice, the field name has "_" and DataField does not. That is why I am removing underscore in my code for one value.
    Wednesday, February 11, 2009 9:12 AM
  • User-2020366656 posted

    Hi,

    Could you guys specify what "local report" means? I want to deploy a web application on GoDaddy.com. This application produces RDLC reports. I also have a hard time to pass parameters required to run the appropriate query to generate this report.

    If I used the above solution, would it work? I am not sure exactly what the local and server report fall into.

    Thanks!

    Friday, July 5, 2013 11:42 AM
  • User-2020366656 posted

    Hi cannot make this work. Here's my code. Could you please look at it and tell me whats is wrong? For your info, my dataset "ds" contains the right data. It must be something to do with configuring the report.rdlc.

     

    ReportViewer1.ProcessingMode = ProcessingMode.Local;
            LocalReport rep = ReportViewer1.LocalReport;
            rep.ReportPath = "C:\\Users\\mathieu\\Documents\\Visual Studio 2010\\WebSites\\JVPay\\Users\\Report.aspx";
    
            DataSet ds = null;
            using (JVPayModel.JVPayEntities context = new JVPayModel.JVPayEntities())
            {
    
                string str_timeStamp = Session["TimeStamp"].ToString();
                var query = (from a in context.Reports
                             where a.TimeStamp == str_timeStamp
                             orderby a.Date
                             select a).ToList();
    
                ds = new DataSet();
                ds = JVPay.ConvertUtil.ToDataSet(query);
            }
    
    
            ReportDataSource dsReportDS = new ReportDataSource();
            dsReportDS.Name = "DataSet1";
            dsReportDS.Value = ds.Tables["Reports"];
            rep.DataSources.Clear();
    
    
            string[] _p1 = new string[] { "param1", Session["TimeStamp"].ToString() };
        
            ReportParameter p1 = new ReportParameter("param1", _p1);
        
            this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1});
    
            rep.DataSources.Add(dsReportDS);
            rep.Refresh();
    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Report.aspx.cs" Inherits="Report" %>
    
    <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
        <rsweb:ReportViewer ID="ReportViewer1" runat="server"
    BackColor="Desktop" BorderColor="Gray"
    Style="color: white; overflow: visible; border-top-width: thin; border-left-width: thin; border-bottom-width: thin; border-collapse: separate; border-right-width: thin;" Width="1000px" LinkActiveColor="White" LinkActiveHoverColor="255, 192, 128" LinkDisabledColor="224, 224, 224" InternalBorderStyle="None" Font-Names="Verdana;color:orange" Font-Size="8pt"
    ShowExportControls="False" BorderStyle="None" BorderWidth="1px"
    Height="400px" SizeToReportContent="True" >
    <LocalReport ReportPath="">
       <DataSources>
           <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
        </DataSources>
      </LocalReport>
    </rsweb:ReportViewer>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetData" 
            TypeName="DataSet1TableAdapters.ReportsTableAdapter" 
            OldValuesParameterFormatString="original_{0}">
        </asp:ObjectDataSource>
    </asp:Content>


    Friday, July 5, 2013 8:14 PM