2012-08-17 41 views
0

我在vb6中有以下代碼,我無法弄清楚如何將它轉換爲C#(Visual Studio 2010)爲我的生活。將vb6轉換爲C#。 Crystal Reports - ParameterFields

VB6 -

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

C#轉換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"; 

每次它進入打印,我得到一個 「缺少的參數值錯誤」

打印部分是正確的,因爲我有其他的代碼,我正在轉換公式字段和那些打印罰款。

關於如何將參數字段行轉換的任何建議?

回答

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 
+0

當我嘗試第一個選項,我得到這個錯誤 - 「參數字段和參數字段的當前值的類型不兼容」任何想法?謝謝。 – user1551783 2012-08-17 15:31:29

+0

我需要引用CRecordset,例如(「GA_PANEL」,recStudy [「GA_PANEL」] ...) – user1551783 2012-08-17 15:32:33

0

我不知道水晶多VB6並沒有什麼,但在C#的等效代碼看起來應該是這樣的:

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

您不需要轉換txtPanelStudy和txtPanelLeg,因爲它們已經是字符串。

+0

txtPanelStudy和txtPanelLeg是文本框,而不是字符串。 VB6隱式引用Text屬性。 – MarkJ 2012-08-18 10:41:57