crystal report 加载报表失败,系统找不到指定的路径 解决方法
折腾了好久,终于搞定了。方法供各位参考!
------------------------------------
会报错的代码如下:
string strsql = "SELECT * from tbl_Basket where orderdate>'2009-01-01'";
DataSet ds = DBUtil.GetDataSet(strsql, strsql);
ReportDocument ReportDoc = new ReportDocument();
if (!ReportDoc.IsLoaded)
{
ReportDoc.Load("Main/CrystalReport.rpt");
}
ReportDoc.SetDataSource(ds.Tables[0]);
this.CrystalReportViewer1.ReportSource = ReportDoc
---------------------------------------------
改成以下代码就可以了:
string strpath = Server.MapPath(@"CrystalReport.rpt");
string strsql = "SELECT * from tbl_Basket where orderdate>'2009-01-01'";
DataSet ds = DBUtil.GetDataSet(strsql, strsql);
ReportDocument ReportDoc = new ReportDocument();
if (!ReportDoc.IsLoaded)
{
ReportDoc.Load(strpath);
}
ReportDoc.SetDataSource(ds.Tables[0]);
this.CrystalReportViewer1.ReportSource = ReportDoc