locked
missing parameters in crystal reports RRS feed

  • Question

  • User-1953456671 posted

    Hi to all, hope someone can help me, i want that when user click the button1 it will get the value on textbox1 and will make it as parameter and will generate the report.

    here is my code:

     private void showReport()
        {
            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
            TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;
            //cryRpt.SetDatabaseLogon("sa", "Qu@lity");
            //cryRpt.SetParameterValue("@employeenumber", TextBox1.Text);
            cryRpt.Load("C:\\Documents and Settings\\ebm\\Desktop\\CrystalReportSite\\CrystalReport.rpt");
            
            crConnectionInfo.ServerName = "Mnl-ebm-xp-ws\\SQLEXPRESS";
            crConnectionInfo.DatabaseName = "QMSRecruitmenttest";
            crConnectionInfo.UserID = "sa";
            crConnectionInfo.Password = "Qu@lity";
            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crTableLogonInfo = CrTable.LogOnInfo;
                crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crTableLogonInfo);
            }
            ParameterFieldDefinitions crParameterFiedDefinitions;
            ParameterFieldDefinition crParameterFiedDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            crParameterDiscreteValue.Value = TextBox1.Text;
            crParameterFiedDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFiedDefinition = crParameterFiedDefinitions["employeenumber"];
            crParameterValues = crParameterFiedDefinition.CurrentValues;
            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFiedDefinition.ApplyCurrentValues(crParameterValues);
            CrystalReportViewer1.ReportSource = cryRpt;
            CrystalReportViewer1.RefreshReport();
        }

    hope someone can advise.

    thanks in advance. :)

    Thursday, July 26, 2012 4:06 AM

All replies

  • User-25924017 posted

    ReuseParameterValuesOnRefresh is set to false ? then try this first:

    cryRpt.ReuseParameterValuesOnRefresh = true;

    because you'r calling refreshreport function after setting parameter.

    Rest of the code looks okay. Also make sure parameter name is correct (case sensitive).

    you can keep cryRpt.SetParameterValue("employeenumber", TextBox1.Text); after setting logon info, don't need @ with parameter.

    Hi to all, hope someone can help me, i want that when user click the button1 it will get the value on textbox1 and will make it as parameter and will generate the report.
    here is my code:
     private void showReport()
        {
            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
            TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;
            //cryRpt.SetDatabaseLogon("sa", "Qu@lity");
            //cryRpt.SetParameterValue("@employeenumber", TextBox1.Text);
            cryRpt.Load("C:\\Documents and Settings\\ebm\\Desktop\\CrystalReportSite\\CrystalReport.rpt");
            
            crConnectionInfo.ServerName = "Mnl-ebm-xp-ws\\SQLEXPRESS";
            crConnectionInfo.DatabaseName = "QMSRecruitmenttest";
            crConnectionInfo.UserID = "sa";
            crConnectionInfo.Password = "Qu@lity";
            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crTableLogonInfo = CrTable.LogOnInfo;
                crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crTableLogonInfo);
            }
            ParameterFieldDefinitions crParameterFiedDefinitions;
            ParameterFieldDefinition crParameterFiedDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            crParameterDiscreteValue.Value = TextBox1.Text;
            crParameterFiedDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFiedDefinition = crParameterFiedDefinitions["employeenumber"];
            crParameterValues = crParameterFiedDefinition.CurrentValues;
            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFiedDefinition.ApplyCurrentValues(crParameterValues);
            CrystalReportViewer1.ReportSource = cryRpt;
            CrystalReportViewer1.RefreshReport();
        }

    hope someone can advise.

    thanks in advance. :)

    Thursday, July 26, 2012 4:59 AM
  • Thursday, July 26, 2012 6:56 AM