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

本文关键字:报告 工作 RDLC 部署 | 更新日期: 2023-09-27 18:05:52

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

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

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