Page 1 of 1
Report>Assign Data from Storedprocedure
Posted: Thu Jan 09, 2014 9:22 am
by kpmsak
Team,
I am keep searching about assign data at runtime. I have stored procedure (SP) which will return data based on some condition, this SP out put i wish to assign stimul soft report (*.mrt) file at runtime.
I have background application (BG App) which will call each *.mrt file and assign data at runtime to generate out put as PDF. Please share sample code for this requirement.
Thanks,
Kpmsak.
Re: Report>Assign Data from Storedprocedure
Posted: Thu Jan 09, 2014 10:58 am
by Alex K.
Hello,
You can fill data from stored procedure to DataSet and pass it to the report with RegData() method.
Also you can add the datasource to report manualy from code:
Code: Select all
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", connectionString));
//Add DataSources:
StiSqlSource DS1 = new StiSqlSource("Connection", "Pr01", "Pr01", "execute Pr01", true, false);
//add parameters
StiDataParameter param = new StiDataParameter("@param1", (int)SqlDbType.Int, 1);
DS1.Parameters.Add(param);
report.Dictionary.DataSources.Add(DS1);
// fill data or schema to dataTableDS1 from SqlDataAdapter or SqlDataReader
//...
//Add Columns:
foreach (DataColumn col in dataTableDS1.Columns)
{
DS1.Columns.Add(col.ColumnName, col.DataType);
}
Thank you.
Re: Report>Assign Data from Storedprocedure
Posted: Thu Jan 09, 2014 12:14 pm
by kpmsak
Hi Aleksey,
Thanks for your swift reply.
I did the same code but report is not working, meanning out put is not display in the viewer. I have checked the stored procedure (SP) it's working fine. This SP has simple SELECT statment no WHERE class notheing else.
Herewith I am pasting my code, please review and post your comment.
Sqlcmd = new SqlCommand();
Sqlcmd.CommandText = "dbo.USP_GetTemplates";
Sqlcmd.Connection = conn;
Sqlcmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(Sqlcmd);
DataSet ds = new DataSet();
da.Fill(ds);
report.Load(@"D:\Reports\t_TemplateDisplay.mrt");
report.Dictionary.Databases.Clear();
report.Dictionary.DataSources.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", connstr));
//Add DataSources:
StiSqlSource DS1 = new StiSqlSource("t_Templates", "t_Templates", "t_Templates", "execute dbo.USP_GetTemplates", true, false);
report.Dictionary.DataSources.Add(DS1);
// fill data or schema to dataTableDS1 from SqlDataAdapter or SqlDataReader
//...
//Add Columns:
foreach (DataColumn col in ds.Tables[0].Columns)
{
DS1.Columns.Add(col.ColumnName, col.DataType);
}
report.Compile();
StiWebViewer1.Report = report;
Thanks,
Kpmsak
Re: Report>Assign Data from Storedprocedure
Posted: Thu Jan 09, 2014 1:09 pm
by Alex K.
Hello,
Please check that in your report used datasources has the similar names with registered data.
Thank you.
Re: Report>Assign Data from Storedprocedure
Posted: Thu Jan 09, 2014 1:21 pm
by kpmsak
Hi,
Thanks, I have modified the datasource name, and executed report. No out out.
Kpmsak.
Re: Report>Assign Data from Storedprocedure
Posted: Thu Jan 09, 2014 5:14 pm
by Andrew
Hello,
Do I understand you correct that the issue is closed?
Thank you.
Re: Report>Assign Data from Storedprocedure
Posted: Fri Jan 24, 2014 8:50 am
by kpmsak
No, still the reported issue is open. Any complete sample code will be appriciated.
Thanks,
Kpmsak
Re: Report>Assign Data from Storedprocedure
Posted: Fri Jan 24, 2014 11:30 am
by Alex K.
Hello,
Please see the sample code in the second post of this topic.
Thank you.