生成报告时遇到问题 [英] I have a problem while generating a report

查看:143
本文介绍了生成报告时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

crystalReportViewer_purchase1.ReportSource = RptDocCrt显示空值。



然后在生成报告时,我收到错误对象引用未设置为实例一个对象。



我尝试过:



crystalReportViewer_purchase1.ReportSource = RptDocCrt shows null value.

and then While generating a report, i have got a error "object reference is not set to an instance of an object."

What I have tried:

public Frm_Purchase_Report(DataSet ds, string p)
       {
           // TODO: Complete member initialization
           this.ds = ds;
           this.p = p;

           try
           {
               string s = ds.Tables[0].Rows.Count.ToString();
               if (s != "0")
               {
                   string AppPath = Application.StartupPath;
                   DataTable dt = new DataTable();
                   AppPath += "\\Report\\genrate_Purchase_Report1.rpt";
                   RptDocCrt.Load(@"" + AppPath);

                   dt = ds.Tables[0];
                   RptDocCrt.SetDataSource(dt);
                   crystalReportViewer_purchase1.ReportSource = RptDocCrt;
                   crystalReportViewer_purchase1.Refresh();

               }
               else
               {
                   MessageBox.Show("Record Not Found..!!!");
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

推荐答案

问题是报告文件的路径。 RptDocCrt.Load无法在提供的路径中找到该文件。



Application.StartUpPath取决于您启动应用程序的方式。

例如,调试StartUp路径时;

<项目路径> \ bin \<调试或发布> \可执行文件



<调试或发布>取决于项目的配置属性。



要确保可以访问报告文件,您需要将报告文件复制到正确的位置,或者放置报告位于备用位置并硬编码文件路径。



注意:如果报告是解决方案的一部分,您可以将报告文件设置为复制到输出位置



亲切的问候
The problem is the path to the Report file. RptDocCrt.Load is unable to locate the file in the provided path.

Application.StartUpPath is dependent on how you are starting the application.
For instance, when debugging the StartUp path will be;
<Path to Project>\bin\<Debug or Release>\Executable

<Debug or Release> is dependent on the configuration properties of the project.

To ensure the report file can be accessed you would need the report files to be copied to the correct location, or put the reports in an alternate location and hard-code the path to the files.

NOTE: If the reports are part of the Solution you can set the report files to be copied to the output location

Kind Regards


这篇关于生成报告时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆