none
Database LogOn Error / Missing Parameters in Crystal reports RRS feed

  • Question

  • 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 8:03 AM