Showing Data from one Datasource based on Data from another Datasource
Hi Folks,
I have 2 data sources in xml format.
Data source 1 contains various operation data.
Data source 2 contains tool data.
Each operation also contains an ID or a name to a used tool from source 2.
I want to make a report exclusively with data from source 2, this is no problem.
But I also want to make a second report that consists mainly of data from source 1, but also shows some information from source 2.
Since source 1 has a reference to source 2 anchored in the XML as described as (numeric) ID or name I should be able to access different columns somehow, right?
Example:
Source 2:
Fields: OperationName | ID_source2 | other...
Source 1:
Fields: OperationName | ID_source2 | other...
Report should show:
OperationName | Description(IDsource2) | Diameter(IDsource2)
I hope you know what I try to achieve. I'm not an expert but I think we talk about the system which is used in databases, known as Primary key/ Forreign Key relationship....
Best regards,
mam
Comments
Hi all,
I figured out how it works and was just a little lost in the documentation!
The key is like I mentioned, to build a relationship. This can be done in the data window. There is a button "Actions" -> New Relation
After building the relation you can use data from both sources combined.
Cheers
mam
Hello!
To retrieve a value from the second data source based on a row key from the first data source, use the Relations feature.
Specify the parent table (ParentTable, with a unique key ParentColumns) and the child table (ChildTable with a foreign key ChildColumns), after which FastReport .NET automatically links the tables and allows you to display the related fields directly via the relationship name or a nested DataBand ([Child.Name] / [RelationName.Field]).
In code, this looks like this:
var rel = new FastReport.Data.Relation { Name = ‘Parts_Ops’, ParentDataSource = report.GetDataSource(‘Parts’), ChildDataSource = report.GetDataSource(‘Ops’), ParentColumns = new[] { ‘PartId’ }, ChildColumns = new[] { ‘PartId’ } }; report.Dictionary.Relations.Add(rel);