用2010cry做的报表,提示未实例化

xianghua 2012-10-31 11:41:19
我刚学水晶报表,请大家指教。
用页面拖了二个控件,一个是CrystalReportViewer,CrystalReportSource
然后写了代码如下:
protected void ForCrystalReport()
{
CrystalReportSource1.ReportDocument.Load(Server.MapPath("zxh.rpt"));
CrystalReportSource1.ReportDocument.SetDatabaseLogon("sa", "000000", "WIN7U-20120704W", "HXDataBase");
CrystalReportSource1.DataBind();

CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.DataBind();
}

protected void CrystalReportViewer1_Init(object sender, EventArgs e)
{
ForCrystalReport();
}

运行时提示“将对象引用设置到对象的实例。 ”,这段代码在VS2008中可以正常。

...全文
67 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xianghua 2012-10-31
  • 打赏
  • 举报
回复
提示这个地方,文件名为空 CrystalReportSource1.ReportDocument.Load("aaa.rpt");
明明有建aaa.rpt的文件,并且是在同一目录
ruanwei1987 2012-10-31
  • 打赏
  • 举报
回复
将对象引用设置到对象的实例

就是那个对象没有实例化就调用了

调试下即知
xianghua 2012-10-31
  • 打赏
  • 举报
回复
在CrystalReportSource1.ReportDocument.Load("aaa.rpt");
这句前加上
CrystalReportSource1.Report.FileName = "aaa.rpt";
就可以了。

CrystalReportSource1.Report.FileName = "aaa.rpt";
CrystalReportSource1.ReportDocument.Load("aaa.rpt");

4,816

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧