我正在尝试使用Crystal studio生成一个报告,该报告从vb.net应用程序中获取一个公共变量。我认为最好的方法是在运行时动态地将过滤器提供给报表,但我无法弄清楚如何设置它以在运行时获取任何信息。有什么建议吗?
答案 0 :(得分: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 结束班
答案 1 :(得分: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();