部署不工作后的RDLC本地报告

时间:2015-08-02 11:57:39

标签: c# winforms deployment rdlc localreport

我使用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();

1 个答案:

答案 0 :(得分:0)

感谢Ganesh R.我设法解决了这个问题。 我通过代码手动提供ReportPath,所以我通过选择ReportViewer上的路径自动给它,它完成了工作。