none
Setting Parameters 101

    Question

  • I'm working in VS 2008 with reports that are migrated from .rdl to .rdlc. I need to run these reports as local reports. I'm having a problem setting the parameters for the reports. The non-working code for opening and setting the parameters is:

    private void cmdNoParam1_Click(object sender, EventArgs e)
    {
        
    string strReport = this.cmdNoParam2.Tag.ToString();
        reportViewer1.LocalReport.ReportEmbeddedResource =
    "Test2." + strReport + ".rdlc";

        ReportParameter[] param = new ReportParameter[1];
        param[0].Name =
    "Cust_Nmbr";
        param[0].Values.Add(
    "ABCD");
        reportViewer1.LocalReport.SetParameters (param);

        ReportDataSource rds = new ReportDataSource();   
        rds.Name =
    "ReportsDataSet_ReportData";
        rds.Value = returnsDataSet.Tables[1];
        reportViewer1.LocalReport.DataSources.Add(rds);

        reportViewer1.RefreshReport();
    }

    In the report parameters, the Parameter is Cust_Nmbr, the Name is Cust_Nmbr, and the Prompt is Cust_Nmbr. Under the Filters property of the table in the report, the Expression is =Fields!CustNmbr.Value, and the Value is Parameters!Cust_Nmbr.Value. The error message I'm getting is The Cust_Nmbr parameter is missing a value.

    I'm new to Visual Studio and Reporting Services, so I need the basics. Also, should I be posting this query in this forum? If not, what forum would be appropriate?

    Thanks.

    Wednesday, July 30, 2008 4:24 PM

All replies

  • I've figured out part of the problem. The new code is:

    ReportParameter param = new ReportParameter();
    param.Name =
    "CustomerID";
    param.Values.Add(
    "XYZ");
    this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { param });

    I no longer get the message about missing parameter value. Now I simply get no data.

    Wednesday, July 30, 2008 9:04 PM
  • You may of figured this out already, but once you succesfully pass the parameter to the report, as it appears you have, in order to call the value use the following expression.


    =Parameters!Cust_Nmbr.Value



    "Fields!" is reserved for values within your datasources.



    Living my life at 123mph in 11.15 seconds
    Thursday, July 31, 2008 2:38 PM
  • Haven't figured it out yet. Where do I use the expression "=Parameters!Cust_Nmbr.Value"? I think part of what's complicating matters for me is that I'm not sure how the C# code and the specific properties of the individual reports interact. I thought learning VS2008/C# on the fly (I have an Access/VBA background) was frustrating! The report side of things is murder.
    Thursday, July 31, 2008 3:08 PM
  •  your code above looks good for handing the parameter to the report.

    But for you to actually use the parameter in the report.  You'd have to decide where/for what it's needed.

    And then you call it by modifiying the expression property for that field in the .RDLC to

    =Parameters!ParamName.Value

    Do you design this parameter to be used with the report? or did someone else design it?   If it use to be a .RDL file, this parameter may of been used to obtain your data, which of course won't work anymore in a .RDLC
    Living my life at 123mph in 11.15 seconds
    Thursday, July 31, 2008 3:14 PM
  • I'm working with a test project and simple reports developed as .rdlc files using the Report Wizard. (My project involves migrating a number of .rdl files to .rdlc - but I'll face that hurdle when I get there.)

    1)  I've established the parameter through the Parameters settings of the Report itself. The name of the parameter is Cust_Nmbr; the Label and Value settings are left blank.

    2)  There is a data table on this report. I've tried setting the Filter for the table in a number of ways, none of which helps. Do I need to be worried about the table at all? (It's not a subreport - just a data table presentation of the primary report data.)

    3)  In the data table, I have tried setting the value of the Customer ID field to "=Parameters!Cust_Nmbr.Value" and to "=Fields!Cust_Nmbr.Value". Neither works.

    Thanks.
    Thursday, July 31, 2008 3:46 PM
  •  To call the value of a parameter, you defiantely use Parameters!ParamName.Value.

    Your code examples above show two different parameter names.  So depending on which one your passing a valid value on, sets your parameter expression.


    =Parameters!Cust_Nmbr.Value
    =Parameters!CustomerID.Value

    1.  my parameters are configured with
        Name
        DataType       generally a string
        Allow Blank Value  checked
        Default Values     null checked


    2.  If you can, I'd pull all parameters, and code out of the report, and make sure your getting at least the data to the table to work, then add parameters.   Applying a parameter to a datatable would usually just be to filter the results. 
    Living my life at 123mph in 11.15 seconds
    Thursday, July 31, 2008 5:14 PM
  • This is getting frustrating! I created a new report with no parameters and can run it just fine. I just can't run it WITH parameters. I've changed a few of the names for clarity. The various settings and name references are:

    1)  The actual field name in the underlying table is CustNmbr.

    2)  The parameter name on the Report Parameters screen is par; data type is string, Allow Blank Value is checked; under Default Values Null is checked. There are no other values set on this screen. Should Label and Value be set? If so,

    3)  Under Filters in the Table Properties for the table on the report, Filters are set to Fields!CustNmbr.Value = Parameters!parCustNmbr.Value.

    4)  Under Data Source Properties, Filters are set exactly as above (3).

    5)  The code with the terminology changes reads as follows:

        ReportParameter param = new ReportParameter();
        param.Name =
    "parCustNmbr";
        param.Values.Add(
    "ALV33133");
        this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { param });

    I get no data. Any thoughts? Any other resources I might refer to?

    Thanks.

    Friday, August 01, 2008 3:02 PM

  • ok, so I guess I'm confused a bit now heh.  I just reread what you put,  The parameter name in the actual report is "Par"  but your giving the report a parameter named something else? "parCustNmbr".   Surprised it even works, since the names don't match.

    First I'd make the names match.   Label and prompt are only used with .rdl format, not .rdlc.




    leave the parameter in the report, but remove it from the filter function on the table.

    Instead, throw a textbox control in the header or footer section of the report.

    And set the expression for the textbox to   =Parameters!Par.Value

    Assuming "Par" is the name you gave the parameter.

    Now, run the report, and make sure the value displayed in the textbox is what you expect to be displayed.






    If the value is correct, then make sure your filter is comparing similar datatypes.

    Comparing int to string will not return results


    Living my life at 123mph in 11.15 seconds
    • Edited by Blasty Friday, August 01, 2008 3:18 PM mistake
    Friday, August 01, 2008 3:14 PM
  • Hi. I made the changes you suggested. The parameter I pass does show up in the textbox in the Header, but the report shows all records, not just the records that meet the criterion. I'm comparing string-to-string, so datatypes should not be the problem.

    Does this sort of stuff drive you nuts the way it does me?

    I do appreciate all your help.
    Friday, August 01, 2008 4:09 PM
  • ok, good, so your value is being passed in, and it appears to be correct.

    Now you can put it back in as a filter and try again.

    Leave the textbox in the header that way you are sure the value is being passed in, and your sure of the value.

    Lets put the filter in as follows


    Expression  =Fields!CustNmbr.Value
    Operator  =
    Value   "ALV33133"


    or whatever you think the parameter should pass in

    the point of doing it this way, is to evaluate how the filter is working, without including the concepts of parameter handling to the troubleshooting.


    I'll tell you what drives me nuts, all the stored procedures I have to write for these reports hehe.  Getting them just right can be a doozy sometimes.
    Living my life at 123mph in 11.15 seconds
    Friday, August 01, 2008 4:33 PM
  • I left everything the same but put the filter (on the table) back in. (The filter on the data source is still set.) I left the text box up, and what it's showing is the filter that I have passed in the code ("RANDOM"), not the filter I've set as the Value of the filter ("ALV33133"). I still get no data.

    Stored procedures can be VERY frustrating. Fortunately, I'm much more familiar with Transact SQL than I am with anything to do with Visual Studio and Reporting Services!
    Friday, August 01, 2008 6:35 PM
  • Hi CaroJ

    try this way...


    _____________________ CS _________________________________________________________
    ReportParameter
     parameter1= new

    ReportParameter("xxxxxxx", "value1");

    ReportParameter parameter2= new

    ReportParameter("yyyyyy", "value1");

    ReportViewer.LocalReport.SetParameters(new ReportParameter[] { parameter1, parameter2});

    _____________________ RDLC ____________________________________________________________

    =Parameters!parameter1.Value

    and 

    =Parameters!parameter2.Value

    ______________________________________________________________________________________

    and if your`r values can be null or blank mark "Allow null value" and "Allow blank value" when u you define parameters...












    Abbas Keshvari... Web Developer and Programmer
    Saturday, August 02, 2008 5:26 AM