Skip to Content
avatar image
Former Member

How to pass parameter sub report in crystal report ?

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"    
       EnableParameterPrompt="False" />

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);

		    /////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);

	 	    /////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);

                    /////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);

                    ReportDocument rdc = new ReportDocument();


                    CrystalReportViewer1.ReportSource = rdc;


When i run , i get error

ErrorMissing parameter values.

How do solution for this ?. Thank all.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Aug 15, 2017 at 07:28 PM

    What SDK are you using?

    Add comment
    10|10000 characters needed characters exceeded

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

    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.

    Add comment
    10|10000 characters needed characters exceeded