我使用 RDLC 构建了一个带有本地报告的 Windows 应用程序,当我在 VS2012 中运行代码时它运行良好,但是当我部署它时,应用程序给了我一些错误:
本地报告处理过程中出现错误。
未指定报告“Report1.rdlc”的报告定义
找不到路径“C:...\Report1.rdlc”的一部分。
我使用的代码:
DataSet2 ds = new DataSet2();
DataTable dt = ds.Table2;
DataRow dr = null;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
dr = ds.Table2.NewRow();
dr["Nr"] = dataGridView1.Rows[i].Cells[0].Value.ToString();
dr["Ary"] = dataGridView1.Rows[i].Cells[1].Value.ToString();
dr["Car"] = dataGridView1.Rows[i].Cells[2].Value.ToString();
dr["Total"] = dataGridView1.Rows[i].Cells[3].Value.ToString();
dr["Total2"] = dataGridView1.Rows[i].Cells[4].Value.ToString();
// MessageBox.Show(dr["Vetura"].ToString());
ds.Table2.Rows.Add(dr);
dt.AcceptChanges();
}
dr.AcceptChanges();
string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
string reportPath = Path.Combine(exeFolder, @"Report1.rdlc");
//MessageBox.Show(reportPath.ToString());
Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet2", ds.Tables[0]);
ra.reportViewer1.LocalReport.DataSources.Clear();
ra.reportViewer1.LocalReport.DataSources.Add(rds);
ra.reportViewer1.LocalReport.ReportPath = reportPath;
if (textBox2.TextLength > 0)
{
ReportParameter Percentage = new Microsoft.Reporting.WinForms.ReportParameter("Percentage", "-" + textBox2.Text + "%");
ReportParameter Total = new Microsoft.Reporting.WinForms.ReportParameter("Total", textBox3.Text);
ra.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Percentage });
ra.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Total });
}
//HERE IS THE FIRST ERROR , WHEN I PASS THE THE TEXT TO THE PARAMETER
ReportParameter Klienti = new Microsoft.Reporting.WinForms.ReportParameter("Klienti", textBox1.Text);
ra.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Klienti });
ra.reportViewer1.RefreshReport();