Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Parameter Dialogue Box Bug Post Reply Post New Topic
Author Message
Brigg
Newbie
Newbie
Avatar

Joined: 14 Jan 2010
Online Status: Offline
Posts: 1
Quote Brigg Replybullet Topic: Parameter Dialogue Box Bug
     Posted: 14 Jan 2010 at 11:05am

I am generating a simple report based on a Parameter that I pass into the report. About every 5the to 6th , sometimes not but every 20th  time that I generate the report the Parameters Dialogue Box pops up and prompts me for the parameter. This is clearly a bug. I have searched the Internet numerous times and can’t find even a reference that anyone else is having this same issue. Below is the class I am using to generate the report. Is there a problem with the code? Is there a way to turn the Parameters Dialogue Box off (Keep it from popping up)? Please help.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using CrystalDecisions.Shared;

 

namespace AECES

{

    public partial class CompRpt : Form

    {

        string SSN = "";

        string crConn;

 

        public CompRpt(string crConnIn, string SSNIn)

        {

            InitializeComponent();

            SSN = SSNIn;

            crConn = crConnIn;

        }

 

        private void CompRpt_Load(object sender, EventArg e)

        {

            Cursor.Current = Cursors.WaitCursor;

            try

            {

 

                CompTaskReport cr = new CompTaskReport();

                CrystalDecisions.Shared.ConnectionInfo crDbConnection = new CrystalDecisions.Shared.ConnectionInfo();

                crDbConnection.DatabaseName = "MyDatabase";

                crDbConnection.ServerName = crConn;

                crDbConnection.IntegratedSecurity = false;

                crDbConnection.UserID = "Mylogin";

                crDbConnection.Password = "MyPassword";

                CrystalDecisions.CrystalReports.Engine.Database crDatabase = cr.Database;

                CrystalDecisions.Shared.TableLogOnInfo oCrTableLoginInfo;

                foreach (CrystalDecisions.CrystalReports.Engine.Table oCrTable in crDatabase.Tables)

                {

                    oCrTableLoginInfo = oCrTable.LogOnInfo;

                    oCrTableLoginInfo.ConnectionInfo = crDbConnection;

                    oCrTable.ApplyLogOnInfo(oCrTableLoginInfo);

                }

 

                crystalReportViewer1.ReportSource = cr;

                ParameterField field1 = this.crystalReportViewer1.ParameterFieldInfo[0];

                ParameterDiscreteValue val1 = new ParameterDiscreteValue();

                val1.Value = SSN;

                field1.CurrentValues.Add(val1);

            }

            finally

            {

                Cursor.Current = Cursors.Default;

            }

        }

    }

}

 

I am using VS 2008 and Crystal Reports Basic

 

Thank you again for the help.

 

 

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 14 Jan 2010 at 2:09pm
I would change the code that sets the parameter so that you're setting it BEFORE setting the ReportSource of the viewer.  Assuming that the parameter name is "SSN", it will look something like this:
cr.ParameterFields["SSN"].AllowCustomValues = true;
cr.ParameterFields["SSN"].CurrentValues.Clear();
cr.ParameterFields["SSN"].CurrentValues.AddValue(SSN);
 
crystalReportViewer1.ReportSource = cr;
 
Also, something to be aware of is that the Crystal assemblies are actually wrappers for COM components.  In .NET, COM components don't always do memory cleanup in a reliable fashion so you have to explicitly dispose of them. 
 
What I generally do is set my report as a class variable and then dispose of it in the FormClosing event handler.  To do this you will move the line "CompTaskReport cr = new CompTaskReport();" from the CompRpt_Load method to just under the "string crConn;" line at the beginning of the class.  You'll then add a FormClosing event handler that will look like this:
private void CompRpt_FormClosing(Object sender, FormClosingEventArgs e)
{
  if (cr != null)
    cr.Dispose();
}
 
This will make sure that the memory used by the report is cleaned up every time the user closes the viewer form.
 
-Dell
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum