Report>Assign Data from Storedprocedure

Stimulsoft Reports.WEB discussion
Post Reply
kpmsak
Posts: 17
Joined: Thu Jan 09, 2014 9:14 am

Report>Assign Data from Storedprocedure

Post 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.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Report>Assign Data from Storedprocedure

Post 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.
kpmsak
Posts: 17
Joined: Thu Jan 09, 2014 9:14 am

Re: Report>Assign Data from Storedprocedure

Post 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
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Report>Assign Data from Storedprocedure

Post by Alex K. »

Hello,

Please check that in your report used datasources has the similar names with registered data.

Thank you.
kpmsak
Posts: 17
Joined: Thu Jan 09, 2014 9:14 am

Re: Report>Assign Data from Storedprocedure

Post by kpmsak »

Hi,

Thanks, I have modified the datasource name, and executed report. No out out.

Kpmsak.
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Re: Report>Assign Data from Storedprocedure

Post by Andrew »

Hello,

Do I understand you correct that the issue is closed?

Thank you.
kpmsak
Posts: 17
Joined: Thu Jan 09, 2014 9:14 am

Re: Report>Assign Data from Storedprocedure

Post by kpmsak »

No, still the reported issue is open. Any complete sample code will be appriciated.

Thanks,

Kpmsak
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Report>Assign Data from Storedprocedure

Post by Alex K. »

Hello,

Please see the sample code in the second post of this topic.

Thank you.
Post Reply