Crystal Report“加载报告失败”在Windows窗体应用程序中 [英] Crystal Report "Load Report Failed" in Windows Form Application
本文介绍了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.
推荐答案
Crystal Reports:修复加载报告失败错误。 [ ^ ]
这篇关于Crystal Report“加载报告失败”在Windows窗体应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文