Page 1 of 1

How to create a report without data.

Posted: Wed Aug 05, 2009 2:59 pm
by mvines
I would like to create a report template based on a data set's schema so that I may define the report in the designer. But I want to bind it to a dataset at run time for the data to be used to fill the report. Essentially, the columns returned are always the same, however, the criteria used to generate the report is always different. Is this something that is possible?

How to create a report without data.

Posted: Wed Aug 05, 2009 4:23 pm
by Brendan
Yes this is possible.

If you want to create a report template based on the structure of a dataset you can register the dataset with the report and enter design mode. This will convert your dataset to a Datasource in the report and you can then work on the datasource to design your report template.

Code: Select all

StiReport report = new StiReport();
report.RegData(myDataSet);
report.Design();
When you want to use the template to present your data, you can load the report template you designed from a file (or other sources), register your dataset that contains the data and preview the report.

Code: Select all

StiReport report = new StiReport();
report.Load(@"c:\myReports\reportTemplate.mrt");
report.RegData(myDataSet);
report.Show();

Also have a look here for some video demonstrations
http://www.stimulsoft.com/ReportsNetVideos.aspx

And there is also a Demo application and some projects that come installed when you install StimulReports.Net. You can find them in your start menu under programs -> stimulsoft or in the stimulsoft installation folder.

How to create a report without data.

Posted: Thu Aug 06, 2009 11:59 am
by mvines
This is almost verbatim what I am currently doing. The only difference I can see is that I am using the WebViewer to render the report.

So I am using the following code in the Page Load event in demo project to try to render the report.

Code: Select all

DataSet resultSet = new DataSet();

using (SqlConnection conn = new SqlConnection(connectionString))
{
    SqlCommand command = new SqlCommand(sqlString, conn);

    SqlDataAdapter adapter = new SqlDataAdapter(command);
    adapter.Fill(resultSet);

    conn.Close();
}

StiReport report = new StiReport();
report.Load(templatePath + "CRTest_Template.mrt");
report.RegData(resultSet);

StiWebViewer1.Report = report;
When I omit the creation of a dataset

Code: Select all

StiReport report = new StiReport();
report.Load(templatePath + "CRTest_Template.mrt");
StiWebViewer1.Report = report;
I get all my records back and the report renders with about 550 pages.

The dataset in my test is filled using the exact same query except that it returns only the top ten results.

When rendering the report with RegData(resultsSet) call I get the stiWebViewer, but I do not see my report template content (header, footer, etc.), nor do I see any of the data in the dataset. What might I be missing?

How to create a report without data.

Posted: Thu Aug 06, 2009 2:32 pm
by mvines
I think I have figured out the missing puzzle piece.

DataSources are named, so:

Code: Select all

StiReport report = new StiReport();
report.RegData(myDataSet);
report.Design();
only gets us part of the way there, we have to explicitly name out datasource.

Code: Select all

StiReport report = new StiReport();
report.RegData("MyDataSource", myDataSet);
report.Design();
then when we are viewing the report, we have to not only RegData our new dataset, but we have to do so by name, so that the existing datasource is overridden.

Code: Select all

DataSet resultSet = new DataSet();

using (SqlConnection conn = new SqlConnection(connectionString))
{
    SqlCommand command = new SqlCommand(sqlString, conn);

    SqlDataAdapter adapter = new SqlDataAdapter(command);
    adapter.Fill(resultSet);

    conn.Close();
}

StiReport report = new StiReport();
report.Load(templatePath + "CRTest_Template.mrt");
report.RegData("MyDataSource", resultSet);

StiWebViewer1.Report = report;
Doing this I have been able to successfully execute my proof of concept project. If my understanding of how this works is not accurate I would appreciate any necessary corrections. I want to understand this process as much as possible, and not just develop a cargo cult code base.

How to create a report without data.

Posted: Thu Aug 06, 2009 4:12 pm
by Edward
Hi

Yes, you are right. RegData registers data in the report Dictionary according with the name of the Connection.

Thank you.