Search code examples
c#crystal-reportssubreport

Crystal Reports for Visual Studio: display 2 unrelated tables


I ask for advice what would you suggest to display 2 unrelated tables in a single report (if needed with subreport), the first one with groupings and the second one "flat"?

Details:

I am developing a report with C# 4 and Crystal Reports for Visual studio. Data comes from a Stored procedure in Sql Server 2005, that returns 2 tables. I pass the data to the report with the .SetDataSource(Dataset) method and I checked that data in the dataset is correct.

I need to display the data from the first table in a quite complex form with different sections. This part works.

At the end of the report I need to print the data from the second table (no grouping, just a "flat" print). To do this I added a subreport.

The tables are not related. I added a Dummy field on them with the same value and used it to mimic a relation in the database expert; I configured the subreport link, based on the dummy field.

I have 2 problems.

The data in the main report is cross joined with the second table (I could expect that since they are related with a constant field)

The subreport is always empty (I checked several times that its table in datasource contains correct data). I tried different configurations of link and tried to place the subreport in different sections (It should be in the report footer). I set a border around the subreport: the border is printed but inside it is empty. I also setup a formula to count the records of both tables and put the count in the report: the count is > 0 for both.


Solution

  • Your approach looks wrong.... At first if both are not releated I don't see any use in creating a dummy field and linking tables which will always provide cross join. Any way as per your descrition table 1 data is saperately displayed and table 2 data is saperately displayed

    As per your description in main report you need data from table 1 and in footer you need data from table 2.

    Try this approach:

    1. Don't link tables

    2. take table 1 in main report and show the required display.

    3. Take sub report and in that take only table 2 and display in footer and make sure don't link main report and sub report nor link two tables.