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:
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();
}
what line is bursting the exception? is in "crParameterFieldDefinition = crParameterFieldDefinitions["user"]; " ?
– Lucas Miranda
crParameterFieldDefinition = crParameterFieldDefinitions["user"]; // points to this line
– Malyster Snur
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
– Lucas Miranda
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.
– Malyster Snur
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
– Lucas Miranda