我在将水晶报告导出为 pdf 时遇到了一些问题。我的程序在加载teleneUdaje.rpt 时崩溃,我确信它是正确的名称。
if (txtpath.Text == "") throw new Exception("Prosím zvoľte cieľovú adresu");
DataSet dt = new DataSet();
string x = nastavenia.adresa_servera();
string y = nastavenia.nazov_databazy();
string z = nastavenia.ponechat_udaje();
string a = nastavenia.sql_meno();
string b = nastavenia.sql_heslo();
SqlConnection databaza = new SqlConnection();
databaza.ConnectionString = "Data Source=" + x + ";Initial Catalog=" + y + ";Persist Security Info=" + z + ";User ID=" + a + "; password=" + b + "";
da.SelectCommand = new SqlCommand("SELECT * FROM tblTepelneUdaje", databaza);
dt.Clear();
da.Fill(dt);
System.IO.FileInfo info = new System.IO.FileInfo(txtpath.Text.Trim());
string type = info.Extension;
CrystalDecisions.Shared.ExportFormatType tp = CrystalDecisions.Shared.ExportFormatType.Excel;
switch (type)
{
case ".pdf":
tp = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
break;
case ".doc":
tp = CrystalDecisions.Shared.ExportFormatType.WordForWindows; break;
case ".rtf":
tp = CrystalDecisions.Shared.ExportFormatType.RichText; break;
case ".xls":
tp = CrystalDecisions.Shared.ExportFormatType.Excel; break;
default: MessageBox.Show("Invalid File type you entered"); break;
}
ReportDocument doc = new ReportDocument();
doc.Load("TeleneUdaje.rpt");
doc.SetDataSource(dt);
doc.ExportToDisk(tp, txtpath.Text);
MessageBox.Show("Zostava bola úspešne exportovaná");
请帮忙。
** 已编辑
它会抛出Crystal Reports 异常,报告加载失败。文件没问题,因为在程序中我可以使用报告查看器工具显示报告。