Page 1 of 1

How to add new datasource in existing report from code?

Posted: Tue Aug 28, 2012 10:55 am
by vatsal24
Hi,

Can you help me adding new datasource (more than one with different connection) to existing report using c#?

Thanks,
Vatsal Desai

Re: How to add new datasource in existing report from code?

Posted: Wed Aug 29, 2012 6:04 am
by Alex K.
Hello,

You can use the following code.
New connection string:

Code: Select all

report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
Add DataSources:

Code: Select all

StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
report.Dictionary.DataSources.Add(DS1);
Add Columns:

Code: Select all

foreach (DataColumn col in dataTableDS1.Columns)
{
     DS1.Columns.Add(col.ColumnName, col.DataType);
}
Add Relations:

Code: Select all

StiDataRelation dataRelation = new StiDataRelation("MyRelation", parentDS, childDS, new string[] { "Field" }, new string[] { "Field" });
report.Dictionary.RegRelations();
report.Dictionary.Relations.Add(dataRelation);
Thank you.

Re: How to add new datasource in existing report from code?

Posted: Wed Aug 29, 2012 10:20 am
by vatsal24
Hi,

Thanks for your help but I am not able to get object "Stimulsoft.Report.Dictionary.StiSqlDatabase" in my application. I have added below references to my project:
Stimulsoft.Base
Stimulsoft.Report
Stimulsoft.Report.Web
Stimulsoft.Report.WebDesigner

Is there any reference missing from my project? Do I need to add any other reference to my project?

Thanks again for your kind help

Vatsal

Re: How to add new datasource in existing report from code?

Posted: Thu Aug 30, 2012 8:17 am
by HighAley
Hello.
vatsal24 wrote:Thanks for your help but I am not able to get object "Stimulsoft.Report.Dictionary.StiSqlDatabase" in my application. I have added below references to my project:
Stimulsoft.Base
Stimulsoft.Report
Stimulsoft.Report.Web
Stimulsoft.Report.WebDesigner

Is there any reference missing from my project? Do I need to add any other reference to my project?
The Stimulsoft.Report.Dictionary.StiSqlDatabase class is in the Stimulsoft.Report assembly.

Thank you.