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

1

How do I create reports through Crystal 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 is blank. The only thing I did after the connection was to select the Data Field's and paste it into the report.

Follow images:

Also follows my flashy report by 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");
    }
    
asked by anonymous 18.02.2014 / 21:36

2 answers

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 with queries with a table. But when checking 2 or more it does not return anything, and I do not know why. To solve the problem I created a new type of Database Field of type Oracle Server, put the tables that I needed and added a line in the code to log in at the time of the flashy 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 the flashy of it without any problem.

    
20.02.2014 / 16:10
1

Something interesting would be to put a DataSet in your project and add to it the tables you will be working with, which are 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 the report creation, it would be enough to select this unique table present in the connection used by the DataSet and the Database Fields .

This article , although you are not doing it exactly, can help you to better understand some of the details of the basic process of creating a report with multiple table association.

    
19.02.2014 / 13:54