locked
Passing Parameters in C# for crystal reports RRS feed

  • Question

  • Hi everyone, 

     

    I am going mental trying to pass simple parameter values from a webform drop down lists to a crystal report in visual studio 2008 (C#). Am currently convering loads of old vs2003 (VB) reports to vs2008 (C#) just solving this problem will help me so much.

    All help much appreciated.

    Code used thus far:

    #region 'Run Report (Crystal)'
        public void celViewReport()
        {
            ConnectionInfo connectionInfo = new ConnectionInfo();
            connectionInfo.ServerName = "xxxxx";
            connectionInfo.UserID = "xxxxx";
            connectionInfo.Password = "xxxxx";

            ReportDocument cryRpt = new ReportDocument();
            string reportPath = Server.MapPath("Course_Enquiry_v4.rpt");
            cryRpt.Load(reportPath);

            cryRpt.SetParameterValue("Grouping 1", this.ddl_group1.SelectedValue);
            cryRpt.SetParameterValue("Grouping 2", this.ddl_group2.SelectedValue);
            cryRpt.SetParameterValue("Parameters", restrictions());

            crvCEL.ReportSource = cryRpt;
            crvCEL.SelectionFormula = criteria;
            crvCEL.RefreshReport();

            SetDBLogonForReport(connectionInfo, cryRpt);

        }


        private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
        {
            Tables tables = reportDocument.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
            {
                TableLogOnInfo tableLogonInfo = table.LogOnInfo;
                tableLogonInfo.ConnectionInfo = connectionInfo;
                table.ApplyLogOnInfo(tableLogonInfo);
            }
        }
        #endregion

    Monday, July 11, 2011 1:36 PM

Answers

  • Hi AJT,

    Try setting the log on info first and then set the parameter values.

    And See these samples on how to:

    https://smpdl.sap-ag.de/~sapidp/012002523100006252812008E/net_web_smpl.exe

    Thank you

    Don


    Don Williams
    Monday, July 11, 2011 9:42 PM
  • Thanks for the reply Don.

    It totally worked just by moving the log on first.   

    "      connectionInfo.Password = "xxxxx";

            ReportDocument cryRpt = new ReportDocument();
            string reportPath = Server.MapPath("Course_Enquiry_v4.rpt");
            cryRpt.Load(reportPath);

            SetDBLogonForReport(connectionInfo, cryRpt);

            cryRpt.SetParameterValue("Grouping 1", this.ddl_group1.SelectedValue);"

     

    Thanks again!

     

     

    Tuesday, July 12, 2011 8:51 AM

All replies

  • Hi AJT,

    Try setting the log on info first and then set the parameter values.

    And See these samples on how to:

    https://smpdl.sap-ag.de/~sapidp/012002523100006252812008E/net_web_smpl.exe

    Thank you

    Don


    Don Williams
    Monday, July 11, 2011 9:42 PM
  • Thanks for the reply Don.

    It totally worked just by moving the log on first.   

    "      connectionInfo.Password = "xxxxx";

            ReportDocument cryRpt = new ReportDocument();
            string reportPath = Server.MapPath("Course_Enquiry_v4.rpt");
            cryRpt.Load(reportPath);

            SetDBLogonForReport(connectionInfo, cryRpt);

            cryRpt.SetParameterValue("Grouping 1", this.ddl_group1.SelectedValue);"

     

    Thanks again!

     

     

    Tuesday, July 12, 2011 8:51 AM