2012-03-28 55 views
0

我正嘗試使用Crystal Studio從vb.net應用程序獲取一個公共變量來生成報表。我認爲最好的方式是在運行時動態地將過濾器賦予報告,但我無法弄清楚如何設置它以在運行時獲取任何信息。有什麼建議?使用VS2010的動態水晶報表Vb.net

回答

0

最好的方法是使用記錄選擇標準中使用的參數來構建報告。然後,您可以加載報告和填充類的參數:

Imports CrystalDecisions.CrystalReports.Engine 
Imports CrystalDecisions.Shared 
Public Class Form1 
Private Sub Button1_Click(ByVal sender As System.Object, _ 
ByVal e As System.EventArgs) Handles Button1.Click 

    Dim cryRpt As New ReportDocument 
    cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") 

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

    crParameterDiscreteValue.Value = TextBox1.Text 
    crParameterFieldDefinitions = - 
     cryRpt.DataDefinition.ParameterFields 
    crParameterFieldDefinition = _ 
     crParameterFieldDefinitions.Item("Customername") 
    crParameterValues = crParameterFieldDefinition.CurrentValues 

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

    CrystalReportViewer1.ReportSource = cryRpt 
    CrystalReportViewer1.Refresh() 
End Sub 

代碼來自:http://vb.net-informations.com/crystal-report/vb.net_crystal_report_parameter_string.htm 末級

0
string query = "select * from TestReport"; 

sqlconn.Open(); 

da = new SqlDataAdapter(query, sqlconn); 

SqlCommandBuilder scb = new SqlCommandBuilder(da); 

da.Fill(DS.TestReport);//DS is a DataSet object . 

myCrystalReport1.SetDataSource(DS); 


//----------------- 

ParameterField paramfield = new ParameterField(); 

ParameterFields paramfields = new ParameterFields(); 

ParameterDiscreteValue discreteval = new ParameterDiscreteValue(); 


paramfield.Name = "myfirstname"; 

discreteval.Value = "10"; 


paramfield.CurrentValues.Add(discreteval); 

paramfields.Add(paramfield); 

crystalReportViewer1.ParameterFieldInfo = paramfields; 

//----------------- 

crystalReportViewer1.ReportSource = myCrystalReport1; 


crystalReportViewer1.Refresh(); 

sqlconn.Close();