如何在reportviewer中的SubReport中创建图表

时间:2017-02-25 18:26:34

标签: c# .net reportviewer

我尝试使用子报表和图表创建一个pdf到子报表中,当我创建pdf时,此错误显示:

  

在指定位置找不到子报表“子报表”   〜\ ReciboCargoConceptos.rdlc。请验证子报告是否已经存在   已发布且名称正确。

....我添加了subProcessingEvent

    var appDomain = AppDomain.CurrentDomain;
    var basePath = appDomain.RelativeSearchPath ?? appDomain.BaseDirectory;
    var path = Path.Combine(basePath, "Vistas", "ReciboTres" + ".rdlc");

    var reporteLocal = new ReportViewer();
    reporteLocal.Reset();
    reporteLocal.LocalReport.DataSources.Clear();

    if (File.Exists(path))
        reporteLocal.LocalReport.ReportPath = path;

    var utils = new Utils();

    DataTable dt = GetResult();
    reporteLocal.LocalReport.DataSources.Add(new ReportDataSource("DSRecibo", dt));

    reporteLocal.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(CargoConceptoSubReport);

方法SubreportProcessingReport

    void CargoConceptoSubReport(object sender, SubreportProcessingEventArgs e)
    {
        int idContrato = int.Parse(e.Parameters["IdContrato"].Values[0]);
        var dtGrafica= GetGrafica(idContrato);
        ReportDataSource datasource= new ReportDataSource("Grafica", dtGrafica);
        e.DataSources.Add(datasource);
    }

方法GetGrafica

private DataTable GetGrafica(int id)
    {
        DataTable resultTable = new DataTable();
        SqlConnection conn = new SqlConnection("ConnectionString");

        try
        {

            using (conn)
            {
                string query = @"select top 24 Consumo.ConsumoAgua, PeriodoFacturacion.FechaFinal, PeriodoFacturacion.Id from Consumo inner join PeriodoFacturacion on " +
                                "PeriodoFacturacion.Id = Consumo.IdPeriodoFacturacion where Consumo.IdContrato = " + id + " order by PeriodoFacturacion.FechaFinal desc";
                SqlCommand cmd = new SqlCommand(query, conn);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    resultTable.Load(reader);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            conn.Close();
        }
        return resultTable;
    }

PDF With Error SubReport With Chart

0 个答案:

没有答案