Unable to use relations between datasources

Stimulsoft Reports.NET discussion
Post Reply
JeffB
Posts: 17
Joined: Fri Dec 18, 2009 9:24 am
Location: Toulouse (France)

Unable to use relations between datasources

Post 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
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: Unable to use relations between datasources

Post 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
JeffB
Posts: 17
Joined: Fri Dec 18, 2009 9:24 am
Location: Toulouse (France)

Re: Unable to use relations between datasources

Post 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
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: Unable to use relations between datasources

Post 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
Post Reply