编程语言
首页 > 编程语言> > c# – Winform ReportViewer并为ServerReport正确设置参数

c# – Winform ReportViewer并为ServerReport正确设置参数

作者:互联网

我正在设置我在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;
    }
}

谢谢,

标记

解决方法:

我在这里找到了问题.我有代码在Form构造函数中设置路径,URL,参数和刷新报表.我将它移动到Form.Load事件中,它现在工作正常.报告仍然正常运行,但现在参数也在ReportViewer顶部的标准部分中正确设置.

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

标签:c,visual-studio-2010,net-4-0,reporting-services,report-viewer2010
来源: https://codeday.me/bug/20190630/1337320.html