【问题标题】:Passing parameters from ReportViewer through to stored procedure data source for SSRS report将参数从 ReportViewer 传递到 SSRS 报告的存储过程数据源
【发布时间】:2011-04-29 23:05:49
【问题描述】:

我正在为 SSRS 2008 R2 的 BIDS 开发一份报告,该报告使用存储过程作为其数据源。我已经在报告中设置了参数,报告将它们传递给存储过程,一切正常。但是,我现在需要转换报表,以便它获取从 C# ASP.Net 应用程序中的 ReportViewer 控件传递给它的参数,而不是允许在 SSRS 界面中输入它们。我认为我在 C# 方面很好(使用 ServerReport.SetParameters),但我不知道如何在 BIDS 中将这些传入的参数值路由到存储过程。谁能举个例子?

我还需要阻止报表显示用于输入参数的 UI。我应该将参数设置为隐藏还是内部?

【问题讨论】:

    标签: reportviewer reporting-services


    【解决方案1】:

    我会将报告参数设置为内部,但请阅读这篇文章 http://msdn.microsoft.com/en-us/library/aa337234.aspx 的隐藏和内部参数部分,并自行决定适合该问题的方法。

    假设你有一个类似的存储过程

    CREATE PROCEDURE dbo.RepeatAfterMe
    (
        @inputText varchar(50)
    ,   @repeatFactor int = 10
    )
    AS
    BEGIN
        SET NOCOUNT ON
        DECLARE @count int
        DECLARE @hack TABLE (inputText varchar(50))
    
        SET @count = 0
        WHILE @count < @repeatFactor
        BEGIN
            INSERT INTO @hack SELECT @inputText
            SET @count = @count + 1
        END
        SELECT H.* FROM @hack H
    END
    GO
    

    在 SSRS 中定义 2 个报表参数(InputText 为字符串,RepeatFactor 为整数)。然后,在您的 SSRS 中,您的数据集将被定义为

    执行 dbo.RepeatAfterMe @inputText, @repeatFactor

    然后在数据集的参数选项卡上,它看起来像

    @inputText =Parameters!InputText.Value 
    @repeatFactor =Parameters!RepeatFactor.Value
    

    为了解决方案的完整性,这是我用来将参数传递到 ID 为 rvReportViewer 的报告控件的代码的近似值

    Microsoft.Reporting.WebForms.ReportParameter[] reportParameters = null;
    reportParameters = new Microsoft.Reporting.WebForms.ReportParameter[2];
    reportParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("inputText", txtInput);
    reportParameters[1] = new Microsoft.Reporting.WebForms.ReportParameter("repeatFactor", 10);
    try
    {
        rvReportViewer.ServerReport.SetParameters(reportParameters);
    }
    catch(Microsoft.Reporting.WebForms.ReportServerException ex)
    {
        Response.Redirect("~/Error.aspx");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多