Crystal Report“加载报告失败”在Windows窗体应用程序中
问题描述:
private void MyReport_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
FileDataSet1 ds = new FileDataSet1(); // .xsd file name
DataTable dt = new DataTable();
dt.TableName = "Crystal Report Example";
dt = getAllOrders(); //This function is located below this function
ds.Tables[0].Merge(dt);
try
{
string rPath = Directory.GetCurrentDirectory();
int index = rPath.ToLower().IndexOf("bin");
if (index >= 0)
{
rPath = rPath.Substring(0, index);
}
rPath = rPath + @"FileMenu\CrystalReport2.rpt";
rptDoc.Load(rPath);
rptDoc.SetDataSource(ds);
crystalReportViewer1.ReportSource = rptDoc;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
public DataTable getAllOrders()
{
string sqlCon = ".....";
SqlConnection Con = new SqlConnection(sqlCon);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter adapter;
try
{
Con.Open();
cmd.CommandText = "select * from Account_Details";
cmd.Connection = Con;
ds = new System.Data.DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "Users");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (Con.State != ConnectionState.Closed)
Con.Close();
}
return ds.Tables[0];
}
此代码在VS2010中运行良好。但是,当我创建此项目的.exe文件时,无法通过显示错误消息加载报告失败来加载报告文件。
需要此问题的帮助。
This code is run well in VS2010. But when i create an .exe file of this project the report file could not load by showing an error message "Load Report Failed".
Need Help for this issue.