日期:2014-05-20  浏览次数:21001 次

水晶报表 --未将对象引用设置到对象的实例

其中用到水晶报表来显示数据
使用的是vs2008 和 水晶报表(CrystalReports 2008)

报表设计也没有问题(包括抓取数据源,xsd和连接数据库的方式都行)

网页加载时的代码如下:
  
  //初始化报表
  Report = new ReportDocument();

  //在类中获取报表的相对地址
  string reportPath = System.Web.HttpContext.Current.Server.MapPath(ReportName);

  //加载报表  
  Report.Load(reportPath);
   
  //设置报表源
  Report.SetDataSource(ds.Tables[TableName]);
  //用报表控件显示报表数据
  CrystalReportViewer.ReportSource = Report;
  //绑定
  CrystalReportViewer.DataBind();
  //刷新最新数据
  Report.Refresh();

每次运行时,都报“未将对象引用设置到对象的实例”错误,都还没运行起来呢
而且错误位置是指向那个报表文件的(***.rpt),行:1

望各位大哥帮帮忙!

------解决方案--------------------
将那个报表文件(***.rpt)放到debug文件夹下面

------解决方案--------------------
字段不对,测试一下你的sql语句。
如果你的sql语句里有sum或count之类的,记得加上别名
如count(*) as 水晶报表中的字段

------解决方案--------------------
1://加载报表
Report.Load(reportPath);
后面加一句
Response.Write(reportPath); 看路径是不是对,别想当然

2:删掉
 //绑定
CrystalReportViewer.DataBind();
//刷新最新数据
Report.Refresh();