Skip to Content

Report keep on passing the data based on default parameters values

Hey,

I am currently developing a desktop app to manage account based personal annual expenses in c# using generic repository pattern with entity framework. I have developed a crystal report to produce report based on 2 parameters: 1) Account GUID and 2) ZYear.

The second parameter values are being replaced which are passed programmatically but GUID are not changing. It just pick up the GUID of first user even when i am logging into with another user.

My codebehind:

if (printReportOnOffToolStripMenuItem.Checked)

{ this.Width = 1084; this.Height = 478;

ParameterFieldDefinitions parameterFieldDefinitions;

ParameterFieldDefinition parameterFieldDefinition;

ParameterValues parameterValues = new ParameterValues();

zakatreport crystalReport1 = new zakatreport();

ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();

try {

//crystalReport1.RefreshReport += (ss, ee) => // { // crystalReport1.ParameterFields.Clear(); // };

//crystalReportViewer1.Refresh();

//crystalReportViewer1.RefreshReport();

//parameterValues.Clear();

parameterDiscreteValue.Value = guid.ToString();

parameterFieldDefinitions = crystalReport1.DataDefinition.ParameterFields;

parameterFieldDefinition = parameterFieldDefinitions["AID"];

parameterValues = parameterFieldDefinition.CurrentValues; parameterValues.Add(parameterDiscreteValue); parameterDiscreteValue.Value = comboBox1.Text;

parameterFieldDefinitions = crystalReport1.DataDefinition.ParameterFields; parameterFieldDefinition = parameterFieldDefinitions["ZYear"];

parameterValues = parameterFieldDefinition.CurrentValues; parameterValues.Add(parameterDiscreteValue); parameterFieldDefinition.ApplyCurrentValues(parameterValues); crystalReportViewer1.ShowRefreshButton = false; crystalReportViewer1.ShowCopyButton = false;

crystalReportViewer1.ShowExportButton = false;

crystalReportViewer1.ReportSource = crystalReport1; }

catch (Exception ex)

{ MessageBox.Show(ex.Message); } }

else { this.Width = 548; this.Height = 478; }

Edit:

After some revisions, i am now getting asked GUID everytime,

i just want to pass both the parameters based on logged in user and view report.

guid.png (43.7 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Aug 22, 2018 at 05:30 PM

    Make sure that you have "Save Data With Report" turned OFF on the File menu in Crystal.

    Have you reviewed Don Williams sample application found here: https://blogs.sap.com/2016/02/17/how-to-parameters-in-crystal-reports-for-visual-studio-net/.

    It contains best practice information for setting parameters and for printing reports.

    Also, I might simplify your code so that it looks something like this:

    parameterFieldDefinitions = crystalReport1.DataDefinition.ParameterFields;
    
    parameterFieldDefinition = parameterFieldDefinitions["AID"];
    parameterValues = parameterFieldDefinition.CurrentValues; 
    parameterValues.Add(parameterDiscreteValue); 
    parameterDiscreteValue.Value = comboBox1.Text;
    parameterFieldDefinition.ApplyCurrentValues(parameterValues); 
    
    parameterFieldDefinition = parameterFieldDefinitions["ZYear"];
    parameterDiscreteValue.Value = guid.ToString();
    parameterValues = parameterFieldDefinition.CurrentValues; 
    parameterDiscreteValue.Value = guid.ToString();
    parameterValues.Add(parameterDiscreteValue); 
    parameterFieldDefinition.ApplyCurrentValues(parameterValues); 
    

    Your original code is only applying the value for one of the parameters. Also, you don't need to get the "parameterFieldDefinitions" twice.

    -Dell

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.