How to create reports in Cristal Report with data from 2 or more tables?

Asked

Viewed 1,634 times

1

How do I create reports by Cristal Reports, using a Dataset that contains more than one Table? With a table I can work normal, but when I insert more than one table the result of the Report comes blank. The only thing I did after the connection was select the Data Fields and paste in the report.

Follows images:

O DataSet utilizado no relatório

Aqui é o próprio relatório

Also follows my flashy report by the MVC:

    public ActionResult relatorio_pdf()
    {
        connectionRateio.ConectarBanco(modelLoginRateio);

        DataTable dataTable = new DataTable();

        var query = @"SELECT * FROM MYTABLE MT INNER JOIN MYOTHERTABLE MOT ON MT.ID = MOT.ID";

        var command = new OracleCommand(query, connectionRateio.connection);


        var dataAdapter = new OracleDataAdapter(command);
        dataAdapter.Fill(dataTable);

        ReportClass rptH = new ReportClass();

        rptH.FileName = Server.MapPath("~/Views/Relatorios/relatorio.rpt");
        rptH.Load();
        rptH.SetDataSource(dataTable);

        Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

        connectionRateio.FecharConexaoBanco();

        return File(stream, "application/pdf");
    }
  • It doesn’t hurt to ask: If you make one SELECT * FROM MYTABLE MT INNER JOIN MYOTHERTABLE MOT ON MT.ID = MOT.ID in the database it returns the results?

  • Rs... Yes, yes. Query is right.

2 answers

1

Something interesting would be to put in your project a Dataset and add to it the tables you will be working with, these being accompanied by an additional Tableadapter that is built from your query

SELECT * FROM MYTABLE MT INNER JOIN MYOTHERTABLE MOT ON MT.ID = MOT.ID

Then, at the time of creating the report, it would be enough to select this single table present in the connection used by Dataset and the Database Fields desired.

This article, although not doing it exactly, it may help you to better understand some details of the basic creation process of a report with multi-table association.

  • I’m still trying to solve the problem but I can’t. I’ve remade it 5 times, I created a new one and the same thing happens. It returns null values when presenting two tables of a Datafield.

0


I was able to find the problem and a solution!

The Database Field configured above is a Database Field of type XML, in which it has full compatibility to queries with a table. However when consulting 2 or more it does not return anything, and I do not know why. To solve the problem I created a new kind of Database Field Oracle Server type, I put the tables I needed and added a line in the code to log in at the time of the flashing report, follow the line:

public ActionResult relatorio_pdf()
{
    ...
    rptH.SetDatabaseLogon("usuario.banco","senha123");// <-Esta linha..
    ...
}

By doing this my report can understand the Join’s made in his flashy without any trouble.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.