Page 1 of 1

Unable to use relations between datasources

Posted: Thu Dec 07, 2017 2:37 pm
by JeffB
Hi,

I am using this code to create a relation between two datasources:

Code: Select all

this.report = new StiReport();
this.report.RegData(source.Key, source.Key, source.Value);
this.report.RegData(source.Key, source.Key, source.Value);
...
this.report.Dictionary.Synchronize();
					
foreach (KeyValuePair<string, object> var in this.relations)
{
	DataRelation relation = var.Value as DataRelation;
	if (relation == null) continue;

	StiDataRelation dataRelation = new StiDataRelation(
		"rel_" + relation.Name,
		relation.Name,
		relation.Name,
		this.report.Dictionary.DataSources[relation.ParentSource.Name],
		this.report.Dictionary.DataSources[relation.ChildSource.Name], 
		relation.ParentColumns.ToArray(),
		relation.ChildColumns.ToArray());
	this.report.Dictionary.Relations.Add(dataRelation);
}

this.report.Dictionary.RegRelations();

this.report.Load(this.TemplateFile);
There is no error at compilation and execution, but the relation doesn't exist into the dictionary in design mode, and so I cannot use it into my databand by the Data Relation property.
Do you know where the problem can coming from?

Thank you.

Jean-François

Re: Unable to use relations between datasources

Posted: Fri Dec 08, 2017 6:55 am
by Edward
Hi Jean-François,

It looks like you are loading the report template after registering relations in the report dictionary, please try to load the report template before doing that.

Please check the sample code on how the relations could be easily registered:
viewtopic.php?&t=2047

Thank you,
Edward

Re: Unable to use relations between datasources

Posted: Mon Dec 11, 2017 3:48 pm
by JeffB
Good answer, it works!

And also, the RegRelations() must be placed BEFORE adding a new relation (and I don't know why ...).

Thank you !
Jean-François

Re: Unable to use relations between datasources

Posted: Tue Dec 12, 2017 6:34 am
by Edward
Hi Jean-François,

Thank you for letting us know that it worked.
The RegRelations() should just register the created relations correctly. Please let us know if you have any issues with that approach.

Thank you,
Edward