0

我在 vb6 中有以下代码,我无法弄清楚如何将其转换为 C#(Visual Studio 2010)。

VB6 -

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

C# 转换尝试-

    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";

每次打印时,我都会收到“缺少参数值错误”

打印部分是正确的,因为我有其他代码在其中转换公式字段并且打印正常。

关于如何转换参数字段行的任何建议?

4

2 回答 2

1

目前您没有设置参数值,您正在设置提示文本。有多种以编程方式设置参数值的方法,这取决于您如何绑定报表、数据源等。下面我说明了 2 个选项,但它实际上取决于您的设置,哪个适合您。

// 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
于 2012-08-17T15:11:01.067 回答
0

我对 VB6 了解不多,对 Crystal 也一无所知,但 C# 中的等效代码应如下所示:

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

您不需要转换 txtPanelStudy 和 txtPanelLeg,因为它们已经是字符串。

于 2012-08-17T15:11:03.890 回答