Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Winforms ReportViewer并正确设置ServerReport的参数_C#_Visual Studio 2010_.net 4.0_Reporting Services_Report Viewer2010 - Fatal编程技术网

C# Winforms ReportViewer并正确设置ServerReport的参数

C# Winforms ReportViewer并正确设置ServerReport的参数,c#,visual-studio-2010,.net-4.0,reporting-services,report-viewer2010,C#,Visual Studio 2010,.net 4.0,Reporting Services,Report Viewer2010,我正在为在ReportViewer控件中显示的报表设置参数,并且参数设置正确,报表正在使用正确的参数运行,但是没有选择在ReportViewer顶部提供报表条件的实际控件。为什么在标准中没有选择正确的项目,即使报表使用我设置的标准正确运行 ReportParameter month = new ReportParameter("month", "September 2011"); SsrsReportInfo reportInfo = new SsrsReportInfo("Summary",

我正在为在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;
    }
}
//
///报表查看器的SSRS报表信息。
/// 
公共类SsrsReportInfo
{
/// 
///初始化类的新实例。
/// 
///报告的名称。
///报表服务器URL。
///报告路径。
公共SsrsReportInfo(字符串reportName、字符串reportServerUrl、字符串reportPath)
:这(reportName、reportServerUrl、reportPath、null)
{            
}
/// 
///初始化类的新实例。
/// 
///报告的名称。
///报表服务器URL。
///报告路径。
///报告参数。
公共SsrsReportInfo(字符串reportName、字符串reportServerUrl、字符串reportPath、参数ReportParameter[]reportParameters)
{
this.ReportName=ReportName;
this.ReportServerUrl=ReportServerUrl;
this.ReportPath=ReportPath;
this.Parameters=reportParameters;
}
/// 
///获取或设置报表的名称。
/// 
///报告的名称。
公共字符串报告名
{
得到;
设置
}
/// 
///获取或设置报表服务器URL。
/// 
///报表服务器URL。
公共字符串ReportServerUrl
{
得到;
设置
}
/// 
///获取或设置报表路径。
/// 
///报告路径。
公共字符串报告路径
{
得到;
设置
}
/// 
///获取或设置参数。
/// 
///参数。
公共报表参数[]参数
{
得到;
设置
}
}
谢谢


马克

我已经解决了这个问题。我让代码在表单构造函数中设置路径、url、参数并刷新报表。我将它移动到Form.Load事件中,现在它可以正常工作了。报告仍然正常运行,但现在参数也在ReportViewer顶部的“条件”部分中正确设置

我在这里使用了相同的用法:,但是注意到他们是在Form.Load事件中使用的,我尝试了一下,结果成功了。我可能也可以在ReportViewer.Load事件中执行此操作,原因可能是在设置值之前尚未在屏幕上绘制控件