将参数从 ReportViewer 传递到 SSRS 报告的存储过程数据源

发布于 2024-11-04 20:32:28 字数 310 浏览 0 评论 0原文

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

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

I have a report I am developing in BIDS for SSRS 2008 R2 that uses a stored procedure as its data source. I have set up parameters in the report and the report is passing them on to the stored procedure and everything works fine. However, I now need to convert the report so it gets its parameters passed to it from a ReportViewer control in a C# ASP.Net application instead of allowing them to be entered in the SSRS interface. I think I am fine on the C# side (using ServerReport.SetParameters), but I don't know what to do in BIDS to route those passed-in parameter values to the stored procedure. Can anyone provide an example?

I also need to prevent the report from displaying the UI for entering the parameters. Should I set the parameters to Hidden or Internal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢望 2024-11-11 20:32:28

我会将报告参数设置为“内部”,但请阅读本文 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");
}

I would set the report parameters as Internal but read up on this article http://msdn.microsoft.com/en-us/library/aa337234.aspx for the section Hidden and Internal Parameters and decided for yourself what is appropriate to the problem.

Assuming you have a stored proc like

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

Define 2 report parameters in SSRS (InputText as string, RepeatFactor as integer). Then, in your SSRS, your dataset would be defined like

EXECUTE dbo.RepeatAfterMe @inputText,
@repeatFactor

And then on the Parameters tab of the dataset, it would look like

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

For completeness of solution, this is an approximation of the code I use to pass parameters in to a report control with an ID of 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");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文