Skip to Content
0

How to pass parameter sub report in crystal report ?

Aug 14, 2017 at 01:17 PM

45

avatar image
Former Member

I create Crystal report from Dataset with pass parameter "UserID" . Then, i do step by step:
1) Create main report with DatasetA, name of report "rpt_MainA" and no set "Parameter Field".
2) Create sub report B with DatasetB, name of report "rpt_SubB" .
3) Create sub report C with DatasetC, name of report "rpt_SubC".
4) Click "Change Subreport Link" of sub report B and choose filed to link "USER_INFO.UPID = USER_EDU.UPID" (with USER_INFO.UPID filed of datasetA, USER_EDU.UPID filed of datasetB)

5) Click "Change Subreport Link" of sub report C and choose filed to link "USER_INFO.UPID = USER_LANG.UPID" (with USER_INFO.UPID filed of datasetA, USER_LANG.UPID filed of datasetC).

# Set properties of report as :

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"    
       HasDrillUpButton="False"   
       HasDrilldownTabs="False" 
       EnableDrillDown="False" 
       EnableParameterPrompt="False" />
</asp:Content>

And this is code behind

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var UserID = "U00001";
                using (GENEntities db = new GENEntities())
                {
                    var con = ((SqlConnection)db.Database.Connection);
                    con.Open();

		    /////bind datasetA - main report , data get from store procedure
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "USER_INFO";
                    cmd.Parameters.AddWithValue("@UID", UserID);
                    cmd.Connection = con;
                    DataTable dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);

	 	    /////bind datasetB - sub report B , data get from store procedure
                    SqlCommand cmd1 = new SqlCommand();
                    cmd1.CommandType = CommandType.StoredProcedure;
                    cmd1.CommandText = "USER_EDU";
                    cmd1.Parameters.AddWithValue("@UID", UserID);
                    cmd1.Connection = con;
                    DataTable dt1 = new DataTable();
                    SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
                    da1.Fill(dt1);


                    /////bind datasetC - sub report C , data get from store procedure
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandType = CommandType.StoredProcedure;
                    cmd2.CommandText = "USER_LANG";
                    cmd2.Parameters.AddWithValue("@UID", UserID);
                    cmd2.Connection = con;
                    DataTable dt2 = new DataTable();
                    SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
                    da2.Fill(dt2);

                    ReportDocument rdc = new ReportDocument();
                    rdc.Load(Server.MapPath("~/REPORT/rpt_Employee.rpt"));

                    rdc.Subreports["rpt_MainA"].SetDataSource(dt1);
                    rdc.Subreports["rpt_SubB"].SetDataSource(dt2);
                    rdc.Subreports["rpt_SubC"].SetDataSource(dt3);

                    rdc.SetDataSource(dt);
                    CrystalReportViewer1.ReportSource = rdc;

                    con.Close();
                }       
            }
        }

When i run , i get error

ErrorMissing parameter values.

How do solution for this ?. Thank all.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member Aug 16, 2017 at 10:37 AM
0

Dear Don Williams
Thank for your reply , I founded solution for this matter "delete all parameter filed" in crystal report, because i defined all them in code behind.
It's working for now.
Thank you sir.

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Aug 15, 2017 at 07:28 PM
0

What SDK are you using?

Share
10 |10000 characters needed characters left characters exceeded