如何分配数据集与许多表到CrystalViewer

本文关键字:许多表 CrystalViewer 数据集 何分配 分配 | 更新日期: 2023-09-27 18:12:25

我需要分配一个数据集(与许多表),到一个ReportDocument,然后分配给CystalReportViewer。

但是用这个代码我不能显示报告。我该怎么做??

protected void btnGenerarErrores_Click(object sender, EventArgs e)
{
    if (txtNumeroBoleta.Text.Trim().Length > 0)
    {
        ReportDocument reporte = new ReportDocument();
        var ruta = Server.MapPath("ReporteErroresPorBoleta.rpt");
        reporte.Load(ruta);
        string parametro = txtNumeroBoleta.Text;
        clsReportesBoletaDat reportesBoleta = new clsReportesBoletaDat();
        DataSet setErrores = reportesBoleta.RetornarBoletasPorASA(parametro);
        DataSet dsNuevo = setErrores.Copy();
        reporte.SetDataSource(dsNuevo.Tables.ToString());
        CrystalReportViewer1.ReportSource = reporte;
        //if (setErrores.Tables.Count > 0)
        //{          
        //    CrystalReportViewer1.ReportSource = reporte;               
        //}
        txtNumeroBoleta.Text = "";
    }
}

如何分配数据集与许多表到CrystalViewer

首先为报表对象清除现有的数据源连接:

reporte.DataSourceConnections.Clear();

你不需要复制你的数据集,你只需要将数据源设置为原始数据集:

reporte.SetDataSource(setErrores);

如果数据集中的表名与报告中的表名/别名不匹配,您可能需要单独设置它们:

reporte.Tables["ReportTable"].SetDataSource(setErrores.Tables["DataSetTable"]);

然后将查看器的报告源设置为您的报告并刷新它:

CrystalReportViewer1.ReportSource = reporte;
CrystalReportViewer1.RefreshReport();