adding datasource through C# code and executing query from it

Stimulsoft Reports.NET discussion
Post Reply
Praveen
Posts: 5
Joined: Thu Jan 21, 2010 10:50 pm
Location: Bangalore

adding datasource through C# code and executing query from it

Post by Praveen »

HI All,

I am using Stimulsoft Reporting Tool for generating reports by fetching data from the DataSource.
But now I want to add a dataset through C# code and want the report to fetch data using this data source query.

I an using the following code in my aspx.cs page:::


Stimulsoft.Report.StiReport stiReport1;
string connString=@"Data Source=SKELTADTP114\SQLEXPRESS;Integrated Security=True;Initial Catalog=ReportDatabase";
con=new SqlConnection(connString);
con.Open();
string query="SELECT t1.Id, t1.Number, t1.Title, t1.Description,t2.RiskCategory, t3.name FROM SKERM t1 LEFT OUTER JOIN SKERMRisk t2 ON t2.RecordParentItemId = t1.Id AND t1.Version = t2.Version LEFT OUTER JOIN SKVirtualActor t3 ON t3.id= t1.owner WHERE t1.ItemType = 2";
SqlDataAdapter ad =new SqlDataAdapter(query,con);
DataSet ds=new DataSet();
ds.DataSetName = "DynamicDataSource";
ds.Tables.Add("RiskTable");
ad.Fill(ds,"RiskTable");

stiReport1 = new StiReport();
stiReport1.Dictionary.DataStore.Clear();
string strpath = HttpContext.Current.Server.MapPath(string.Empty);
stiReport1.Load(strpath + "\\RiskRegister.mrt");

stiReport1.Dictionary.Databases.Clear();
stiReport1.Dictionary.Databases.Add(new StiSqlDatabase("Connection",connString));
stiReport1.RegData("RiskTable",ds);
stiReport1.Dictionary.Synchronize();
stiReport1.Compile();
StiWebViewer1.Report = stiReport1;


after executing this code , the reports is still generated using the quey from the datasource specified in the report design but not the query from the code.

Please help me in this.
Thanks in advance.


Regards

Praveen
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

adding datasource through C# code and executing query from it

Post by Jan »

Hello Praveen,

Please check following code:

Code: Select all

stiReport1 = new StiReport();
stiReport1.Dictionary.DataStore.Clear();
string strpath = HttpContext.Current.Server.MapPath(string.Empty);
stiReport1.Load(strpath + "\\RiskRegister.mrt");

stiReport1.Dictionary.Databases.Clear();
stiReport1.Dictionary.DataSources.Clear();
stiReport1.RegData("RiskTable",ds);
stiReport1.Dictionary.Synchronize();
stiReport1.Compile();
StiWebViewer1.Report = stiReport1;
Thank you.
Post Reply