Skip to Content
0

Make a multiple page report: crystal report viewer only generates first page (C#)

Mar 15, 2017 at 03:58 PM

382

avatar image

I'm creating an application using windows forms and c#. I'm trying to generate a multiple page report on a same viewer using a list of numbers extracted from a Datagridview, but crystal report viewer only generates first page even though I pass more than one parameter for the store procedure of the crystal report viewer.

What I want is: For each parameter, generate the report that corresponds to that parameter in the same report viewer but in a different page each report, using the same store procedure for all the parameters. For instance: I pass the parameter 1, the report viewer shows the report #1 in page #1, I pass the parameter 2, the report viewer shows the report #2 in page #2 and so on.

What am I missing? or what am I doing wrong?

Thanks in advance.

This is the code to load my report:

using System;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using MySql.Data.MySqlClient;

namespace Sistema_Facturacion
{
public partial class frmReporteTodasFacturas : Form
{
    public int NumeroFactura { get; set; }
    public IList<int> ListaFacturas { get; set; }

    public frmReporteTodasFacturas()
    {
        InitializeComponent();
    }

    private void crystalReportViewer1_Load(object sender, EventArgs e)
    {
        ReportDocument Reporte = new ReportDocument();


        ParameterFields arregloParametros = new ParameterFields();
        ParameterField FacturaNumero = new ParameterField();
        FacturaNumero.Name = "p_idFactura";

        //for each Number in the list generate a different report in a different page

        foreach (int NoFactura in ListaFacturas)
        {
            ParameterDiscreteValue valorNumeroFactura = new ParameterDiscreteValue();
            valorNumeroFactura.Value = NoFactura;
            FacturaNumero.CurrentValues.Add(valorNumeroFactura);
            arregloParametros.Add(FacturaNumero);
        }

        this.crystalReportViewer1.ParameterFieldInfo = arregloParametros;
        string path =
        Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "Reportes" +
            System.IO.Path.DirectorySeparatorChar + "TodasFacturasSistemaFacturacion.rpt";
        Reporte.Load(path);


        string CadenaConexion = ConfigurationManager.ConnectionStrings["MySQLAutentication"].ToString();

        MySqlConnectionStringBuilder CSB = new MySqlConnectionStringBuilder(CadenaConexion);            

        string BaseDatos= CSB.Database;
        string Usuario = CSB.UserID;
        string Contrasena = CSB.Password;
        string Puerto = CSB.Port.ToString();
        string Servidor = "Driver={MySQL ODBC 5.3 Unicode Driver};Server=" + CSB.Server + ";" +"Port="+ Puerto + ";" +"Option=3;";

        ConnectionInfo ciReportConnection = new ConnectionInfo();

        ciReportConnection.ServerName = Servidor;
        ciReportConnection.DatabaseName = BaseDatos;
        ciReportConnection.UserID = Usuario;
        ciReportConnection.Password = Contrasena;


        foreach (Table table in Reporte.Database.Tables)
        {
            table.LogOnInfo.ConnectionInfo = ciReportConnection;
            table.ApplyLogOnInfo(table.LogOnInfo);
        }

        foreach (ReportDocument subrep in Reporte.Subreports)
        {
            foreach (Table table in subrep.Database.Tables)
            {
                table.LogOnInfo.ConnectionInfo = ciReportConnection;
                table.ApplyLogOnInfo(table.LogOnInfo);
            }
        }


        if (this.crystalReportViewer1.LogOnInfo != null)
        {
            TableLogOnInfos tlInfo = this.crystalReportViewer1.LogOnInfo;
            foreach (TableLogOnInfo tbloginfo in tlInfo)
            {
                tbloginfo.ConnectionInfo = ciReportConnection;
            }
        }

        crystalReportViewer1.ReportSource = Reporte;

        crystalReportViewer1.Refresh();
    }
  }
}
c#
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Don Williams
Mar 22, 2017 at 01:25 PM
0
Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Mar 15, 2017 at 04:00 PM
0

What SDK are you using and what patch level?

Not the Assembly version, need to know the dll version.

Share
10 |10000 characters needed characters left characters exceeded