Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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# ReportParameter异常错误_C#_Winforms_Reportviewer - Fatal编程技术网

C# ReportParameter异常错误

C# ReportParameter异常错误,c#,winforms,reportviewer,C#,Winforms,Reportviewer,嗨,我已经开发了一个网站与报告功能,它的工作没有任何问题。现在我想开发一个Windows窗体应用程序和具有报告功能的C#。这就是我所做的: private void print_Load(object sender, EventArgs e) { rptViewer.Reset(); DataTable dt = getData("2"); ReportDataSource rds = new ReportDataSource("DataS

嗨,我已经开发了一个网站与报告功能,它的工作没有任何问题。现在我想开发一个Windows窗体应用程序和具有报告功能的C#。这就是我所做的:

private void print_Load(object sender, EventArgs e)
    {
        rptViewer.Reset();
        DataTable dt = getData("2");
        ReportDataSource rds = new ReportDataSource("DataSet1", dt);
        rptViewer.LocalReport.DataSources.Add(rds);
        rptViewer.LocalReport.ReportPath = @"PAL\Report1.rdlc";
        ReportParameter[] rptParams = new ReportParameter[] {
        new ReportParameter("invoiceId","2")
        };
        rptViewer.LocalReport.SetParameters(rptParams);
        rptViewer.LocalReport.Refresh();
        this.rptViewer.RefreshReport();
    }
另一个填充数据表的功能:

private DataTable getData(string id)
    {
        string[] dataName = new string[1];
        dataName[0] = "@invoiceId";
        string[] dataValue = new string[1];
        dataValue[0] = id;
        DataTable dt = new DataTable();
        dt = _cls.FillDataTable("procBasket", dataName, dataValue);
        return dt;
    }
但是当我运行程序时,VS抛出如下错误:
VS似乎找不到报告路径并抛出以下异常:

异常:引发:“找不到路径“C:\Users\BNS\Documents\Visual Studio 2013\Projects\nickSell\nickSell\bin\Debug\PAL\Report1.rdlc”的一部分。”(System.IO.DirectoryNotFoundException) 引发System.IO.DirectoryNotFoundException:“找不到路径“C:\Users\BNS\Documents\Visual Studio 2013\Projects\nickSell\nickSell\bin\Debug\PAL\Report1.rdlc”的一部分。” 时间:2015/12/27星期日下午7:53:53 线程:[10268]

我为路径做了一些操作,但错误仍然存在:(

最后是我的解决方案树视图

而具有reportview控件的打印winform路径如下:

尝试
应用程序。改为启动

改变这个,

string exeFolder = Path.GetDirectoryName(Application.ExecutablePath);
进入

编辑:根据我们的报告,问题在于报告路径实际上位于解决方案可执行文件的父文件夹的父文件夹中。这就是发生错误的原因

要更正错误,只需执行以下操作转到报告文件夹:

string dir = Directory.GetParent(Application.StartupPath).FullName; 
dir = Directory.GetParent(dir).FullName; //get parent of parent folder
string reportPath = Path.Combine(dir , @"PAL\Report1.rdlc"); //then do this
rptViewer.LocalReport.ReportPath = reportPath;    

通过这种方式,报告路径指向正确文件夹中的正确文件。解决此问题的关键是正确获取文件夹

这很奇怪,您是否检查了
报告路径
(修改后)调试模式下的值?它是否真的具有正确的报告路径值?问题是VS希望从调试文件夹中读取报告文件,但我的报告文件位于解决方案文件夹中。这对我来说很奇怪。我想我必须更改一些内容…我更改为
string exeFolder=Application.StartupPath;
,但得到相同的错误:(好吧,这真的很奇怪=(但您是否检查了
reportPath
字符串值是什么?这是组合后的路径:
C:\\Users\\BNS\\Documents\\visualstudio 2013\\Projects\\nickSell\\nickSell\\bin\\Debug\\PAL\\Report1.rdlc
。这是我的计算机上的物理路径:
C:\Users\BNS\Documents\visualstudio 2013\Projects\nickSell\nickSell\PALRe。)port1.rdlc
。好的,实际报告不在
nickSell\\nickSell\\bin\Debug\`
等中。让我们来看看。
string exeFolder = Application.StartUp;
string dir = Directory.GetParent(Application.StartupPath).FullName; 
dir = Directory.GetParent(dir).FullName; //get parent of parent folder
string reportPath = Path.Combine(dir , @"PAL\Report1.rdlc"); //then do this
rptViewer.LocalReport.ReportPath = reportPath;