0

I have the following code in vb6 and I cannot figure out how to convert it to C# (visual studio 2010) for the life of me.

vb6 -

    crtPanelStudyAuditTrail.ParameterFields(0) = "GA_PANEL;" & Trim(txtPanelStudy) & ";True"
    crtPanelStudyAuditTrail.ParameterFields(1) = "GA_PANEL_LEG;" & Trim(txtPanelLeg) & ";True"

C# conversion attempt-

    crtrptPanelStudyAuditTrail.DataDefinition.ParameterFields["GA_PANEL"].PromptText = "GA_PANEL;" + txtPanelStudy.ToString().Trim() + ";True";
    crtrptPanelStudyAuditTrail.DataDefinition.ParameterFields["GA_PANEL_LEG"].PromptText = "GA_PANEL_LEG;" + txtPanelLeg.ToString().Trim() + ";True";

Every time it gets to print, I get a "missing parameter value error"

The print part is correct because I have other code where I am converting formulafields and those print fine.

Any suggestions on how I can convert the parameterfield lines??

user1551783
  • 83
  • 1
  • 8

2 Answers2

1

Currently you are not setting the parameter value, you are setting the prompting text. There are multiple ways to set the parameter values programatically it just depends on how you are binding your report, datasource, etc. Below I have illustrated 2 options but it really depends on your setup as to which one will work for you.

// Assuming "GA_PANEL" is the name of your parameter this is the simplest way to set it but depends on how you are binding the report
crtrptPanelStudyAuditTrail.SetParameterValue("GA_PANEL", "GA_PANEL;" + txtPanelStudy.ToString().Trim() + ";True");   


// Second method gives more flexibility in the types of parameters such as date, discrete, multi, etc.
// Create a parameter value
var paramVal = new ParameterDiscreteValue();
paramVal.Value = "GA_PANEL;" + txtPanelStudy.ToString().Trim() + ";True");

// Clear the current and default values from your parameter
crtrptPanelStudyAuditTrail.ParameterFields["GA_PANEL"].CurrentValues.Clear();
crtrptPanelStudyAuditTrail.ParameterFields["GA_PANEL"].DefaultValues.Clear();

// Add your values to the parameter value collection
crtrptPanelStudyAuditTrail.ParameterFields["GA_PANEL"].CurrentValues.Add(paramVal);
crtrptPanelStudyAuditTrail.ParameterFields["GA_PANEL"].HasCurrentValue = true;

// Refresh your report
Justin
  • 2,093
  • 1
  • 16
  • 13
  • When I try the first option i get this error - "The types of the parameter field and parameter field current values are not compatible" Any ideas? Thank you. – user1551783 Aug 17 '12 at 15:31
  • Would I have to reference the CRecordset such as ("GA_PANEL", recStudy["GA_PANEL"]...) – user1551783 Aug 17 '12 at 15:32
0

I don't know much VB6 and nothing about Crystal, but the equivalent code in C# should look something like this:

crtrptPanelStudyAuditTrail.ParameterFields[0] = @"GA_PANEL;" + txtPanelStudy.Trim() + @";True";
crtrptPanelStudyAuditTrail.ParameterFields[1] = @"GA_PANEL_LEG;" + txtPanelLeg.Trim() + @";True";

You don't need to convert txtPanelStudy and txtPanelLeg as they are already strings.

AnnieMacD
  • 58
  • 5
  • txtPanelStudy and txtPanelLeg are textboxes, not strings. VB6 implicitly references the Text property. – MarkJ Aug 18 '12 at 10:41