Error - string C# for Crystal Report

Asked

Viewed 84 times

1

When trying to pass the string from c# Windows Forms to Crystal Report following the procedure of the second image and the code below Crystal report shows the following error! Visual Studio Community 2017, Mysql free and Crystal Report Sap.

Error:

inserir a descrição da imagem aqui

Code:

private void Form2_Load(object sender, EventArgs e)
{
    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load("C:\\Users\\Rafael\\Desktop\\ProG\\Gold Business - Another\\Gold Business\\CrystalReport1.rpt");

    ParameterFieldDefinitions crParameterFieldDefinitions;
    ParameterFieldDefinition crParameterFieldDefinition;
    ParameterValues crParameterValues = new ParameterValues();
    ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

    crParameterDiscreteValue.Value = usuario;
    crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
    crParameterFieldDefinition = crParameterFieldDefinitions["usuario"];
    crParameterValues = crParameterFieldDefinition.CurrentValues;

    crParameterValues.Clear();
    crParameterValues.Add(crParameterDiscreteValue);
    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh();
}

Calling in the Crystal Report: inserir a descrição da imagem aqui

  • what line is bursting the exception? is in "crParameterFieldDefinition = crParameterFieldDefinitions["user"]; " ?

  • crParameterFieldDefinition = crParameterFieldDefinitions["user"]; // points to this line

  • Most likely you are not passing the name, in the case "user", correct, if I were you would put a breakpoint there and take a look at the Collection de crParameterFieldDefinitions to see if you find the actual name of your field

  • sorry I am novice with Crystal Report, as I must pass in the parameter the "string" user to make connection with the code written above must be there the error, is passing in the parameter, in Crystal report, in the second image below.

  • Man, honestly it’s easier to do what I said, if you open Collection there will be able to see the name of your parameters correctly, but if I’m not mistaken I think you need to put a @ before the parameter name, maybe that’s it

1 answer

0


I think you can replace all this one-parameter assignment code with this:

cryRpt.SetParameterValue("usuario", "Eu!");

After this substitution may even fail to give you error, if the parameter actually exists in the report.

  • It’s the same mistake! and points to this cryRpt line.Setparametervalue("user", "I!") in the case only has in Crystal Report the parameter "user" in the case as I should pass the parameter is as in the second image above.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.