Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: How to pass parameter to Subreport using C#? Post Reply Post New Topic
Author Message
tahmeed
Newbie
Newbie
Avatar

Joined: 19 Apr 2010
Location: Bangladesh
Online Status: Offline
Posts: 2
Quote tahmeed Replybullet Topic: How to pass parameter to Subreport using C#?
    Posted: 19 Apr 2010 at 7:16pm
Dear Experts,
Please help me to send parameter programetically to Crystal Report Subreport from C#. I can pass parameter to the main report using the following way:

ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("rptMainReport.rpt");
ParameterFields parameterFields = new ParameterFields();
ParameterField parameterField = new ParameterField();
parameterField.ParameterFieldName = "myRoleID";
ParameterDiscreteValue parameterValue = new ParameterDiscreteValue();
parameterValue.Value = 2;
parameterField.CurrentValues.Add(parameterValue);
parameterFields.Add(parameterField);
CrystalReportViewer1.ParameterFieldInfo = parameterFields;
CrystalReportViewer1.ReportSource = cryRpt;


but having problem to send parameter to subreport. so please help me sending example code.

Thanx in advance


Edited by tahmeed - 19 Apr 2010 at 7:17pm
Tahmeed Ahmed
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 19 Apr 2010 at 7:46pm
Are you using .NET 2005/2008? If so, just do this:
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("rptMainReport.rpt");
cryRpt.SetParameterValue("myRoleId", 2, "subreport name");

and fill in the proper value for the subreport name.

I cover this in Chapter 16 of my CR.NET programming book.
http://www.amazon.com/exec/obidos/ASIN/097495361X/bischofsystem-20
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
tahmeed
Newbie
Newbie
Avatar

Joined: 19 Apr 2010
Location: Bangladesh
Online Status: Offline
Posts: 2
Quote tahmeed Replybullet Posted: 19 Apr 2010 at 8:44pm
Thanx BrianDischof.
Tahmeed Ahmed
IP IP Logged
Lakshmi kanth
Newbie
Newbie


Joined: 02 Oct 2011
Location: India
Online Status: Offline
Posts: 1
Quote Lakshmi kanth Replybullet Posted: 02 Oct 2011 at 12:13am
Thanks a lot u saved my weekend
IP IP Logged
NimaEntesari
Newbie
Newbie


Joined: 14 Dec 2012
Online Status: Offline
Posts: 2
Quote NimaEntesari Replybullet Posted: 14 Dec 2012 at 6:13am
hello dears,
i use your code to pass parameter to subreport like code below:

SqlConnection cnn;
            string connectionString = null;
            string sql = null;

            connectionString = "data source=.;initial catalog=Lab2;Integrated Security=yes;";
            cnn = new SqlConnection(connectionString);
            cnn.Open();
            sql = @"EXEC    [dbo].[pro_PrintReceptionReceptionInfo]" +
                            "@ReceptNum = '" + receptionNum + "'" +

                  @"EXEC    [dbo].[pro_PrintReceptionPatientTest]" +
                            "@ReceptionNum = '" + receptionNum + "'" +

                  @"EXEC    [dbo].[pro_PrintReceptionPatientInfo]" +
                            "@PatientNum = '" + patientNum + "'" +

                  @"EXEC    [dbo].[pro_PrintReceptionDepositFund]" +
                            "@ReceptNum = '" + receptionNum + "'";

            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
            DataSet ds = new DataSet();
            dscmd.Fill(ds, "ReceptionInfo, PatientTest, PatientInfo, DepositFund");
            cnn.Close();

            ParameterFields pFields = new ParameterFields();

            ParameterField pf = new ParameterField();
            ParameterDiscreteValue pdv = new ParameterDiscreteValue();
            pdv.Value = int.Parse(receptionNum);
            pf.Name = "@ReceptNum";
            pf.CurrentValues.Add(pdv);

            ParameterField pf2 = new ParameterField();
            ParameterDiscreteValue pdv2 = new ParameterDiscreteValue();
            pdv2.Value = int.Parse(receptionNum);
            pf2.Name = "@ReceptionNum";
            pf2.CurrentValues.Add(pdv2);

            ParameterField pf3 = new ParameterField();
            ParameterDiscreteValue pdv3 = new ParameterDiscreteValue();
            pdv3.Value = Int64.Parse(patientNum);
            pf3.Name = "@PatientNum";
            pf3.CurrentValues.Add(pdv3);
           
            ParameterField pf4 = new ParameterField();
            ParameterDiscreteValue pdv4 = new ParameterDiscreteValue();
            pdv4.Value = int.Parse(receptionNum);
            pf4.Name = "@ReceptNum";
            pf4.CurrentValues.Add(pdv4);

            pFields.Add(pf);
            pFields.Add(pf2);
            pFields.Add(pf3);
            pFields.Add(pf4);

            crystalReportViewer1.ParameterFieldInfo = pFields;

            ReceptionPrint objRpt = new ReceptionPrint();
            objRpt.SetDataSource(ds);
            objRpt.SetParameterValue("@ReceptionNum", int.Parse(receptionNum), "ReceptionPrintTest");
            objRpt.SetParameterValue("@ReceptNum", int.Parse(receptionNum), "DepositPrintSubReport");

            crystalReportViewer1.ReportSource = objRpt;

but when report loads, it send a message that say "the parameter is incorrect

thanks alot
Smile
IP IP Logged
NimaEntesari
Newbie
Newbie


Joined: 14 Dec 2012
Online Status: Offline
Posts: 2
Quote NimaEntesari Replybullet Posted: 16 Dec 2012 at 12:39pm
Please help me about this, please :(
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.015 seconds.