This is a migrated thread and some comments may be shown as answers.

SubReports and Parameters

1 Answer 158 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Doug Odegaard
Top achievements
Rank 2
Doug Odegaard asked on 20 Aug 2008, 05:53 PM
I have been searching the documentation and examples but nothing definitive on this.  Product Line Sales is not comprehensive enough unfortunately.  So here is my question....

I need to create a Report + Subreport (which itself contains a subreport)

These need to be linked so for each detail record in the Report it will run the subreport (and subsequently that subreport).  The big thing is the passing of the Parameters to each.  Can anyone help me with an example or documentation on how to do this?  Crystal Reporting does a great job of Linked Subreports and am interested in achieving this.  When I accomplish this I will post as sample code for all to use.

Thanks.
Doug

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 21 Aug 2008, 12:09 AM
This is how I like to pass parameters to my subreports.

I create all my datasource dynamically in the code.  Because I connect to a IBM database server.

And I use the NeedDataSource event on all my reports, main and sub-reports, and then I pull the fields i need from the row, and then build a sql connection with those fields during that event.


The NeedDataSource event is an event that all the other report tools seem to lack.  It's what seperates Telerik from the rest.

This works if you leave your subreport datasource field empty.  That way this event will trigger.


example
ponumber is the parameter that I use in my main report, and then my supreport needs to only match by the po#.

private void subReport1_NeedDataSource(object sender, System.EventArgs e)

{

Telerik.Reporting.Processing.

ReportItemBase itemBase = (Telerik.Reporting.Processing.ReportItemBase)sender;

// pull the PO# from my main report datasource PHPOID
string
ponumber = (string)((System.Data.DataRowView)(itemBase.DataItem))["PHPOID"];

 

Telerik.Reporting.Processing.

SubReport subrpt = (Telerik.Reporting.Processing.SubReport)sender;

DataRowView drv = (DataRowView)subrpt.DataItem;

try

{

iDB2Connection connDB2 = new iDB2Connection(ConfigurationManager.AppSettings["InfiniumPM"]);

 

string sqlretrieve =

" SELECT * FROM cadbfa.dmlnd,cadbfa.dmlnh WHERE CADBFA.DMLND.NDFLOG= CADBFA.DMLNH.NHFLOG and " +

" CADBFA.DMLNH.NHNOTY = 'PMPPH' and CADBFA.DMLNH.NHLIN# = 0 and " +

" CADBFA.DMLND.NDSTS <> '99' and CADBFA.DMLNH.NHsts <> '99' and " +

" cadbfa.dmlnh.nhpt02 = '1' and NHNOKY = '" + ponumber + "' " +

" ORDER BY " +

" CADBFA.DMLNH.NHTITL, CADBFA.DMLND.NDSEQ ";

connDB2.Open();

iDB2DataAdapter adapter = new iDB2DataAdapter();

adapter.SelectCommand =

new iDB2Command(sqlretrieve, connDB2);

DataSet dataSet = new DataSet();

int x = adapter.Fill(dataSet);

subrpt.InnerReport.DataSource = dataSet;

subrpt.InnerReport.DataMember =

"Table";

connDB2.Close();

}

catch (System.Exception ex)

{

// An error has occurred while filling the data set. Please check the exception for more information.

System.Diagnostics.

Debug.WriteLine(ex.Message);

}

}

Tags
General Discussions
Asked by
Doug Odegaard
Top achievements
Rank 2
Answers by
Richard
Top achievements
Rank 1
Share this question
or