2013-01-13 96 views
0

我正試圖通過在textbox中輸入客戶代碼來過濾使用Crystal中的參數的客戶。我爲客戶代碼創建了一個參數,並嘗試使用下面顯示的代碼傳遞它的值,但它不起作用。當我點擊按鈕則顯示所有的客戶不僅將過濾的:如何將參數傳遞給Crystal報表?

Imports CrystalDecisions.CrystalReports.Engine 
Imports CrystalDecisions.Shared 

Public Class ParametroCrForm 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

     Dim relatorio As New ReportDocument 

     relatorio.Load("C:\Users\Fernando e Flavia\Documents\Visual Studio 2010\Projects\Crystal.Estudo\Crystal.Estudo\CrystalReport1.rpt") 

     Dim crParameterFieldDefinitions As ParameterFieldDefinitions 
     Dim crParameterFieldDefinition As ParameterFieldDefinition 
     Dim crParameterValues As New ParameterValues 
     Dim crParameterDiscreteValue As New ParameterDiscreteValue 

     If codigoTextBox.Text = "" Then 
      MessageBox.Show("Digite um c�digo de cliente", "Aten��o", MessageBoxButtons.OK, MessageBoxIcon.Stop) 
      Exit Sub 
     End If 

     crParameterDiscreteValue.Value = codigoTextBox.Text 
     crParameterFieldDefinitions = relatorio.DataDefinition.ParameterFields 
     crParameterFieldDefinition = crParameterFieldDefinitions.Item("codigoParametro") 
     crParameterValues.Clear() 
     crParameterValues = crParameterFieldDefinition.CurrentValues 

     crParameterValues.Add(crParameterDiscreteValue) 
     crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) 

     CrystalReportViewer1.ReportSource = relatorio 
     CrystalReportViewer1.Refresh() 

    End Sub 
End Class 
+1

您是否根據該參數在報告中創建了選擇公式? – AbZy

+0

不,我沒有在編碼方面真的很新,我不知道這個額外的步驟,它的工作!非常感謝你!!!! – Fernando

回答

相關問題