Search code examples
c#asp.netcrystal-reports

Why the crystal report not appear and no show?


I created a crystal report and webpage , I want to open crystal report in my webpage depends on the textbox value and i need when click the button i send the values to crystal reports to show my crystal report . I tried the following code , and I set the data source and connection to database :

protected void Button1_Click(object sender, EventArgs e)
    {
        rdoc.Load(Server.MapPath("~/RPT/RPT_CASH_RESULT.rpt"));
        SqlCommand cmd = new SqlCommand("GET_ORDER_RESULT_PRINT_CASH", cn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@ORDER_ID", TXTORDERID.Text);
        cmd.Parameters.AddWithValue("@deptid", TXTDEPTID.Text);
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        rdoc.SetDataSource(dt);
        CrystalReportViewer1.ReportSource = rdoc;
        CrystalReportViewer1.DataBind();

        rdoc.SetDatabaseLogon("DBA", "1234");

    }
}

when click the button its not showing the report only blank screen . what to do to show the report where is the mistake ?

I tried another solution but when click print button its not show the crystal report only blank page what to do i tried alot of solutions available in this site and other site ???

protected void BtnCrystal_Click(object sender, EventArgs e)
        {
            if (Session["patientno"] != null && Convert.ToInt32(Session["patientno"]) > 0)
            {
ReportDocument reportDocument = new ReportDocument();

                ParameterFields paramFields = new ParameterFields();
                ParameterField paramField = new ParameterField();
                ParameterField paramField1 = new ParameterField();
                ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
                ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
                paramField.Name = "@ORDER_ID";
                paramDiscreteValue.Value =Convert.ToInt32(TXTORDERID.Text);
                paramField.CurrentValues.Add(paramDiscreteValue);
                paramFields.Add(paramField);



                paramField1.Name = "@deptid";
                paramDiscreteValue1.Value =Convert.ToInt32(TXTDEPTID.Text);
                paramField1.CurrentValues.Add(paramDiscreteValue1);
                paramFields.Add(paramField1);

                CrystalReportViewer1.ParameterFieldInfo = paramFields;
                reportDocument.Load(Server.MapPath("~/RPT/RPT_CASH_RESULT.rpt"));
                CrystalReportViewer1.ReportSource = reportDocument;
reportDocument.SetDatabaseLogon("DB", "1111","test","DB");
            }

Solution

  • I found finally the solution for this error Why do I get blank page after publish Crystal Reports 13 to IIS?

    1. Downloading and installing runtime for Crystal Reports 13 for Visual Studio 2017. (You might want to skip this step if you already did this before and your application is working locally).

    2. Once the runtime is installed. Crystal Reports will install the required support files in the location of your local computer: C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319\crystalreportviewers13

    3. Copy the entire Crystal Report Support folder C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319\crystalreportviewers13 to your Website's SITE_ROOT\aspnet_client\system_web\4_0_30319 folder.

    4) If you do not have a \aspnet_client\system_web\4_0_30319 folders in your website's root. Please create them manually and then copy the crystalreportviewers13 into it.

    Note: the version number '4_0_30319' is not fixed, it might be changed because of asp.net version. You can try to change this folder name to 4_6_1069 if 4_0_30319 not work.

    I used the following solution to passing parameters from crystal reports using stored procedures with parameters to website and read from sqlserver database :

    ReportDocument reportDocument = new ReportDocument();
                    ParameterFields paramFields = new ParameterFields();
                    ParameterField paramField = new ParameterField();
                    ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
                    ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
                    ParameterField parameterField1 = new ParameterField();
                    ParameterDiscreteValue parameterDiscreteValue1 = new ParameterDiscreteValue();
                    ParameterFields parameterFields = new ParameterFields();
       parameterField1.Name = "@ORDER_ID";
       parameterDiscreteValue1.Value = (object)this.TXTORDERID.Text.ToString();
                                parameterField1.CurrentValues.Add((ParameterValue)parameterDiscreteValue1);
                                parameterFields.Add(parameterField1);
    
                                ParameterField parameterField2 = new ParameterField();
                                ParameterDiscreteValue parameterDiscreteValue2 = new ParameterDiscreteValue();
                                parameterField2.Name = "@deptid";
                                parameterDiscreteValue2.Value = (object)this.TXTDEPTID.Text.ToString();
                                parameterField2.CurrentValues.Add((ParameterValue)parameterDiscreteValue2);
                                parameterFields.Add(parameterField2);
                                this.CrystalReportViewer1.ParameterFieldInfo = parameterFields;
                                this.CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                                this.CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
                                reportDocument.Load(this.Server.MapPath("~/RPT/RPT_CASH_RESULT.rpt"));
                                this.CrystalReportViewer1.ReportSource = (object)reportDocument;
                                reportDocument.SetDatabaseLogon("DB", "111");
    
                                ConnectionInfo connectionInfo = new ConnectionInfo();
                                connectionInfo.ServerName = "server";
                                connectionInfo.DatabaseName = "DBname";
                                connectionInfo.Password = "dbpass";
                                connectionInfo.UserID = "DBuser";
                                connectionInfo.Type = ConnectionInfoType.SQL;
                                connectionInfo.IntegratedSecurity = false;
                                for (int index = 0; index < this.CrystalReportViewer1.LogOnInfo.Count; ++index)
                                    this.CrystalReportViewer1.LogOnInfo[index].ConnectionInfo = connectionInfo;