Click here to Skip to main content
15,359,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

What I have tried:

protected void BtnCrystal_Click(object sender, EventArgs e)
        {
            if (Session["patientno"] != null && Convert.ToInt32(Session["patientno"]) > 0)
            {
              if (Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 )
                {
                  ReportDocument reportDocument1 = new ReportDocument();
                    reportDocument1.Load(Server.MapPath("~/RPT/RPT_CASH_RESULT.rpt"));

                    ParameterFields paramFields1 = new ParameterFields();

                    ParameterField paramField1 = new ParameterField();
                    ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();

                    paramField1 = new ParameterField(); 
                    paramDiscreteValue1 = new ParameterDiscreteValue();  
                    paramField1.Name = "@ORDER_ID";
                    paramDiscreteValue1.Value = TXTORDERID.Text.ToString();
                    paramField1.CurrentValues.Add(paramDiscreteValue1);
                    paramFields1.Add(paramField1);

                    paramField1 = new ParameterField(); 
                    paramDiscreteValue1 = new ParameterDiscreteValue();  
                    paramField1.Name = "@deptid";
                    paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();
                    paramField1.CurrentValues.Add(paramDiscreteValue1);
                    paramFields1.Add(paramField1);



                    CrystalReportViewer1.ParameterFieldInfo = paramFields1;
                    CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                    CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;

                    CrystalReportViewer1.ReportSource = reportDocument1;
                    reportDocument1.SetDatabaseLogon("DB_admin", "1111");
                    }
                }


            }


when click the button its not show the crystal report but when i run the report from visual studio its running what is the missing ?
Posted
Updated 1-Nov-21 21:55pm

   
Comments
Member 13505603 29-Nov-19 1:11am
   
I changed the code but getting now new error :
protected void BtnCrystal_Click(object sender, EventArgs e)
{
if (Session["patientno"] != null && Convert.ToInt32(Session["patientno"]) > 0)
{

SqlCommand cmd = new SqlCommand("GET_ORDER_RESULT_PRINT_CASH", cn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);

ReportDocument reportDocument1 = new ReportDocument();
reportDocument1.Load(Server.MapPath("~/RPT/RPT_CASH_RESULT.rpt"));
reportDocument1.SetDatabaseLogon("DBA", "1111");
reportDocument1.SetParameterValue("@ORDER_ID", TXTORDERID.Text);
reportDocument1.SetParameterValue("@deptid", TXTDEPTID.Text);

reportDocument1.SetDataSource(dt);
CrystalReportViewer1.ReportSource = reportDocument1;
CrystalReportViewer1.DataBind();

var connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "SQL";
connectionInfo.DatabaseName = "DB";
connectionInfo.Password = "1111";
connectionInfo.UserID = "DBA";
connectionInfo.Type = ConnectionInfoType.SQL;
connectionInfo.IntegratedSecurity = false;
for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
{
CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
}
}

when click the button its giving the following error now Additional information: Procedure or function 'GET_ORDER_RESULT_PRINT_CASH' expects parameter '@ORDER_ID', which was not supplied , I already added the parameters where is the error ?
You need to add parameters to the SqlCommand not to the crystal report.

SqlCommand cmd = new SqlCommand("GET_ORDER_RESULT_PRINT_CASH", cn);
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);
   
Comments
Member 13505603 5-Dec-19 23:40pm
   
Thank you sir for helping me
I changed it but still have same error
Procedure or function 'GET_ORDER_RESULT_PRINT_CASH' expects parameter '@ORDER_ID', which was not supplied.
in the line
sda.Fill(dt);

can i make link between datatable and parameters in sda.fill ?
Member 13505603 6-Dec-19 0:31am
   
I tried this now no errors but when i click the button its not show the report :


SqlCommand cmd = new SqlCommand("GET_ORDER_RESULT_PRINT_CASH", cn);
cmd.Parameters.AddWithValue("@ORDER_ID",Convert.ToInt32(TXTORDERID.Text));
cmd.Parameters.AddWithValue("@deptid",Convert.ToInt32(TXTDEPTID.Text));
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
sda.Fill(dt);


ReportDocument reportDocument1 = new ReportDocument();
reportDocument1.Load(Server.MapPath("~/RPT/RPT_CASH_RESULT.rpt"));
reportDocument1.SetDataSource(dt);
CrystalReportViewer1.ReportSource = reportDocument1;
var connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "dba";
connectionInfo.DatabaseName = "DBA";
connectionInfo.Password = "DBA";
connectionInfo.UserID = "DBA";
connectionInfo.Type = ConnectionInfoType.SQL;
connectionInfo.IntegratedSecurity = false;
for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
{
CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
}
Try removing the following lines, I don't think you need those
var connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "dba";
connectionInfo.DatabaseName = "DBA";
connectionInfo.Password = "DBA";
connectionInfo.UserID = "DBA";
connectionInfo.Type = ConnectionInfoType.SQL;
connectionInfo.IntegratedSecurity = false;
for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
{
CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
}
   
Comments
Member 13505603 6-Dec-19 14:32pm
   
Thank you Aung ,
the solution working now the error of show blank screen after publish was the SAP crystal reports runtime engine , I installed runtime engine for crystal reports then I copied the folder aspnet_client under mr site root folder
Aung Than Lwin 6-Dec-19 14:36pm
   
Great!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900