简体   繁体   中英

Crystal Reports Multiple Tables Issue

I have a C# 2010 application that uses Crystal Reports for VS 2010. My report's purpose is to show where a person should be each day of one or more weeks. The format is this:

在此输入图像描述

Please note that it is displayed in pairs, rather than a table with a general header.

It uses a DataSet that contains two DataTables, one for the header dates and one for the location.

The problem is that if I have n items in each DataTable, the report displays n^2 pairs of header / location instead of just n. The pattern is similar to a Cartesian product of the two tables.

I think it might have something to do with the linking part in the report's Database Expert but I couldn't manage to fix it. It contains no links right now.

The DataSet I use looks like this:

在此输入图像描述

Why do you need a table for the headers? What are you trying to accomplish?

Why not add a date (StartOfWeek) to the WeekTable that represents the starting date of the week? If you have that date, each column header would be a formula field that calculates the day based on the StartOfWeek field. So much easier and it eliminates the Cartesian product that you are experiencing.

** edit **

There would be 7 header formulae (one for each day):

//{@Sunday}
DateAdd("d", 0, {WeekTable.StartOfWeek})

...

//{@Saturday}
DateAdd("d", 7, {WeekTable.StartOfWeek})

Add each field to the Page Header section and format as desired (they are Date values).

You need to link the tables to only get n rows.

Ideally:

  • Add a unique ID column to the Headers table. Make it the one primary key, and an auto-incrementing identity.
  • Add a HeaderID column to the WeekTable table, and make it a foreign key to the Headers table on the ID column.

The Headers table should now only include one row for each week, so if you have four employees they will all have the same HeaderID for a given week.

You may need to explain a little further what your "header dates" are. But from what you're saying they are not linked to the main data, in which case i would probably use a subreport in the header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM