Problem setting parameters with ReportViewer

  • I'm trying to use the ReportViewer in a C# project, and am having problems setting the parameters programatically.

    It's got to be something really simple that I'm doing wrong.

    Here's my code:

    private void ViewReport()

    {

    string sReportServer = "MyServer";

    string sReportPath = "/PathToTheReport/ReportName";

    string sReportServerURL = "http://" + sReportServer + "/ReportServer";

    Microsoft.Reporting.WinForms.ReportParameter[] Param;

    // following line getting "Use of unassigned local variable 'Param' " error.

    Param[0] = new Microsoft.Reporting.WinForms.ReportParameter("Param1", "1");

    reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;

    reportViewer1.ServerReport.ReportServerUrl = new Uri(sReportServerURL);

    reportViewer1.ServerReport.ReportPath = sReportPath;

    reportViewer1.ServerReport.SetParameters(Param);

    reportViewer1.ShowParameterPrompts = false;

    reportViewer1.ShowPromptAreaButton = false;

    reportViewer1.RefreshReport();

    }

    Thanks for helping me out!

    Wayne

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Are you declaring your array properly? I'm not an expert C# developer but wouldn't it be...

    Microsoft.Reporting.WinForms.ReportParameter[] Param[];


    Cheers,

    Ben Sullins
    bensullins.com
    Beer is my primary key...

  • I'm not a C# expert either... 🙁

    this gets me the error:

    Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.

    Ben Sullins (4/14/2008)


    Are you declaring your array properly? I'm not an expert C# developer but wouldn't it be...

    Microsoft.Reporting.WinForms.ReportParameter[] Param[];

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Okay, I got it working.

    It should have been:

    Microsoft.Reporting.WinForms.ReportParameter[] Param = new Microsoft.Reporting.WinForms.ReportParameter[1];

    WayneS (4/14/2008)


    I'm not a C# expert either... 🙁

    this gets me the error:

    Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.

    Ben Sullins (4/14/2008)


    Are you declaring your array properly? I'm not an expert C# developer but wouldn't it be...

    Microsoft.Reporting.WinForms.ReportParameter[] Param[];

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply