Winforms ReportViewer 并为 ServerReport 正确设置参数

发布于 2024-12-03 10:59:37 字数 3001 浏览 3 评论 0原文

我正在为在 ReportViewer 控件中显示的报表设置参数,并且参数设置正确并且报表使用正确的参数运行,但是在 ReportViewer 顶部提供报表条件的实际控件并不已选择。即使报表按照我设置的条件正常运行,为什么没有在条件中选择正确的项目?

ReportParameter month = new ReportParameter("month", "September 2011");
SsrsReportInfo reportInfo = new SsrsReportInfo("Summary", "http://server/ReportServer/", "/MyFolder/Summary", month);

this.reportViewer1.ServerReport.ReportPath = reportInfo.ReportPath;
this.reportViewer1.ServerReport.ReportServerUrl = new Uri(reportInfo.ReportServerUrl);

if (reportInfo.Parameters != null)
{
    this.reportViewer1.ServerReport.SetParameters(reportInfo.Parameters);
}

this.reportViewer1.RefreshReport();

这是 reportInfo 类的代码:

/// <summary>
/// SSRS report information for report viewer.
/// </summary>
public class SsrsReportInfo
{
    /// <summary>
    /// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
    /// </summary>
    /// <param name="reportName">Name of the report.</param>
    /// <param name="reportServerUrl">The report server URL.</param>
    /// <param name="reportPath">The report path.</param>
    public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath)
        : this(reportName, reportServerUrl, reportPath, null)
    {            
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
    /// </summary>
    /// <param name="reportName">Name of the report.</param>
    /// <param name="reportServerUrl">The report server URL.</param>
    /// <param name="reportPath">The report path.</param>
    /// <param name="reportParameters">The report parameters.</param>
    public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath, params ReportParameter[] reportParameters)
    {
        this.ReportName = reportName;
        this.ReportServerUrl = reportServerUrl;
        this.ReportPath = reportPath;
        this.Parameters = reportParameters;
    }

    /// <summary>
    /// Gets or sets the name of the report.
    /// </summary>
    /// <value>The name of the report.</value>
    public string ReportName
    {
        get;
        set;
    }

    /// <summary>
    /// Gets or sets the report server URL.
    /// </summary>
    /// <value>The report server URL.</value>
    public string ReportServerUrl
    {
        get;
        set;
    }

    /// <summary>
    /// Gets or sets the report path.
    /// </summary>
    /// <value>The report path.</value>
    public string ReportPath
    {
        get;
        set;
    }

    /// <summary>
    /// Gets or sets the parameters.
    /// </summary>
    /// <value>The parameters.</value>
    public ReportParameter[] Parameters
    {
        get;
        set;
    }
}

谢谢,

马克

I'm setting parameters for a report that I'm showing in ReportViewer control, and the parameters are setting properly and the report is running with the proper parameters, however the actual controls that provide the report criteria at the top of the ReportViewer are not selected. Why aren't the proper items selected in the criteria, even when the report is properly running with the criteria that I set?

ReportParameter month = new ReportParameter("month", "September 2011");
SsrsReportInfo reportInfo = new SsrsReportInfo("Summary", "http://server/ReportServer/", "/MyFolder/Summary", month);

this.reportViewer1.ServerReport.ReportPath = reportInfo.ReportPath;
this.reportViewer1.ServerReport.ReportServerUrl = new Uri(reportInfo.ReportServerUrl);

if (reportInfo.Parameters != null)
{
    this.reportViewer1.ServerReport.SetParameters(reportInfo.Parameters);
}

this.reportViewer1.RefreshReport();

Here's the code for the reportInfo class:

/// <summary>
/// SSRS report information for report viewer.
/// </summary>
public class SsrsReportInfo
{
    /// <summary>
    /// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
    /// </summary>
    /// <param name="reportName">Name of the report.</param>
    /// <param name="reportServerUrl">The report server URL.</param>
    /// <param name="reportPath">The report path.</param>
    public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath)
        : this(reportName, reportServerUrl, reportPath, null)
    {            
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
    /// </summary>
    /// <param name="reportName">Name of the report.</param>
    /// <param name="reportServerUrl">The report server URL.</param>
    /// <param name="reportPath">The report path.</param>
    /// <param name="reportParameters">The report parameters.</param>
    public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath, params ReportParameter[] reportParameters)
    {
        this.ReportName = reportName;
        this.ReportServerUrl = reportServerUrl;
        this.ReportPath = reportPath;
        this.Parameters = reportParameters;
    }

    /// <summary>
    /// Gets or sets the name of the report.
    /// </summary>
    /// <value>The name of the report.</value>
    public string ReportName
    {
        get;
        set;
    }

    /// <summary>
    /// Gets or sets the report server URL.
    /// </summary>
    /// <value>The report server URL.</value>
    public string ReportServerUrl
    {
        get;
        set;
    }

    /// <summary>
    /// Gets or sets the report path.
    /// </summary>
    /// <value>The report path.</value>
    public string ReportPath
    {
        get;
        set;
    }

    /// <summary>
    /// Gets or sets the parameters.
    /// </summary>
    /// <value>The parameters.</value>
    public ReportParameter[] Parameters
    {
        get;
        set;
    }
}

Thanks,

Mark

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

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

发布评论

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

评论(1

(り薆情海 2024-12-10 10:59:37

我已经弄清楚这里的问题了。我有代码在 Form 构造函数中设置路径、url、参数并刷新报告。我将其移至 Form.Load 事件中,现在工作正常。报告仍然可以正常运行,但现在在 ReportViewer 顶部的标准部分中也可以正确设置参数。

我在这里显示了相同的用法:http://technet。 microsoft.com/es-es/library/aa337089(SQL.90).aspx,但是注意到他们在 Form.Load 事件中执行了此操作,我尝试了这一点,并且成功了。我也可以在 ReportViewer.Load 事件中执行此操作,其原因可能是在设置值之前控件尚未在屏幕上绘制。

I've figured out the issue here. I had the code setting the path, url, parameters and refreshing the report within a Form constructor. I moved it into the Form.Load event and it works fine now. Reports still run properly, but now the parameters are properly set also within the criteria portion on the top of the ReportViewer.

I had the same usage shown here: http://technet.microsoft.com/es-es/library/aa337089(SQL.90).aspx, however noticed that they did it in the Form.Load event, and I tried that, and it worked. I could probably do it in the ReportViewer.Load event also, the reason for this is probably that the controls aren't drawn up on screen yet before setting the values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文