Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Calling a Report with SubReports from C# Post Reply Post New Topic
Author Message
sbd2008
Newbie
Newbie


Joined: 22 Oct 2008
Location: Canada
Online Status: Offline
Posts: 1
Quote sbd2008 Replybullet Topic: Calling a Report with SubReports from C#
     Posted: 22 Oct 2008 at 12:51pm
Hi there,
 
I have got a Crystal Report developed with Crystal Reports 2008. I am using ASP.Net 2005 (C#) and am trying to call the report from the web page. I have a couple of questions since I am doing this for the first time.
 
1) Do I need to create a seperate connection to the sub reports too in my
C# code. If yes, how do I do that?
 
2) My report has got two main parameters, Start Date and End Date. Do I have to pass the parameters to the sub reports too from my C# code?
 
Can anyone please help me with this ?
 
Thanks in advance.
Savs.
 
Here is my code :
 

DateTime dtStartDate = DateTime.Parse(tbxFromDate.Text);
DateTime dtEndDate = DateTime.Parse(tbxToDate.Text);
CrystalReportViewer1.ReportSource = Server.MapPath(
"MyReport.rpt");
CrystalReportViewer1..ServerName =
"ServerIP";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID =
"sa";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password =
"";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName =
"DBName";
CrystalReportViewer1.RefreshReport();
ParameterFields myParams = new ParameterFields();
ParameterField myParam1 = new ParameterField();
ParameterField myParam2 = new ParameterField();
ParameterDiscreteValue myDiscreteValue1 = new ParameterDiscreteValue();
ParameterDiscreteValue myDiscreteValue2 = new ParameterDiscreteValue();
myParam1.ParameterFieldName =
"StartDate";
myParam2.ParameterFieldName =
"EndDate";
myDiscreteValue1.Value = dtStartDate;
myParam1.CurrentValues.Add(myDiscreteValue1);
myDiscreteValue2.Value = dtEndDate;
myParam2.CurrentValues.Add(myDiscreteValue2);
myParams.Add(myParam1);
myParams.Add(myParam2);
// Assign the params collection to the report viewer
CrystalReportViewer1.ParameterFieldInfo = myParams;

 
 
IP IP Logged
qasimali84
Newbie
Newbie
Avatar

Joined: 14 Oct 2008
Location: Pakistan
Online Status: Offline
Posts: 27
Quote qasimali84 Replybullet Posted: 23 Oct 2008 at 2:58am
You will add one more CrystalReportViewer2 for your sub report.
Provide the report source and connectioninfo same like main report.

and Assign the params collection to the report viewer2 with only following statement if your date parameters are same for main and sub report

CrystalReportViewer2.ParameterFieldInfo = myParams;


Solution2:

              You can add sub report at report design level
          1. Open your crystal report in design view.
          2. Right click on report footer/Page footer where you want to show
              subreport and select Insert and select sub report
           3. Browse your sub report path.

Hope the answer to your question


Edited by qasimali84 - 23 Oct 2008 at 3:02am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum