Error - C # string for Crystal Report

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 the crystal report shows the following error! Visual Studio Community 2017, Mysql free and Crystal Report Sap.

Error:

Code:

privatevoidForm2_Load(objectsender,EventArgse){ReportDocumentcryRpt=newReportDocument();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();
}

Turning on Crystal Report:

    
asked by anonymous 15.09.2018 / 01:49

1 answer

0

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

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

After this substitution, you can even stop giving it an error, if the parameter actually exists in report .

    
15.09.2018 / 11:39