How to add new datasource in existing report from code?

Stimulsoft Reports.WEB discussion
Post Reply
vatsal24
Posts: 10
Joined: Sat Mar 31, 2012 7:32 am
Location: India

How to add new datasource in existing report from code?

Post by vatsal24 »

Hi,

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

Thanks,
Vatsal Desai
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

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

Post 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.
vatsal24
Posts: 10
Joined: Sat Mar 31, 2012 7:32 am
Location: India

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

Post 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
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

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

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