选择语言,点击下一步,同意SAP BUSINESSOBJECTS license Agreement:
选中Yes,install 64-bit runtime选项。
点击Finish按钮,继续安装。
安装结束,所有安装窗口自动关闭。
打开你的项目,参考下面几个类:
打开Web.Config文档,需要配置Crystal Report:
configSections Source Code
assemblies Source Code
pilation.RptBuildProvider, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
businessObjects Source Code
接下来,为ASP.NET MVC项目添加一页网页是asp.net 的ASPX,网页名为CurrencyReport.aspx,它自带有CurrencyReport.aspx.cs如下图。
对这页网页暂时不需添加任何代码,稍后创建好.Rpt报表后再来写代码。
现在开始创建.rpt水晶报表:
报表创建完毕,此时打开上面创建的ASPX网页。
再打开.aspx.cs代码页,编写加载水晶报表程序:
string reportPath = Server.MapPath("CurrencyReport.rpt");
ReportDocument repDoc= newReportDocument();try{if (!File.Exists(reportPath))
{
Response.Write("指定的报表不存在。 \n");
}
repDoc.Load(reportPath);
repDoc.SetDatabaseLogon("username", "password", "127.0.0.1", "DBname", true);this.CrystalReportViewer1.ToolPanelView =CrystalDecisions.Web.ToolPanelViewType.None;this.CrystalReportViewer1.HasToggleGroupTreeButton = false;this.CrystalReportViewer1.ReportSource =repDoc;
}catch(Exception ex)
{
Response.Write(ex.Message);
}
Source Code
为程序添加水晶报表完成,我们运行程序,结果如下:
什么内容也没有显示,按F12查看,还有crv.js加载失败和bobj is not defind错误。
经过研究与测试,我们还做少一步动作。前往电脑C驱动器:C:\inetpub\wwwroot把aspnet_client整个目录拷贝至项目的根目录之下。
再次运行程序:
数据还是没有显示,水晶报表需要输入连接数据安全信息。
解决这个问题,需要打开加载水晶报表的程序,添加一个方法SetDatabaseLogon,并赋其参数
再次刷新网页,上面的对话框消失,报表已经正常显示了》