水晶报表中的多个参数 [英] multiple parameters in crystal reports

查看:94
本文介绍了水晶报表中的多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在制作一个应用程序时遇到问题,该应用程序可以从Sql Server数据库中添加,读取和操作数据.该应用程序还使用数据参数生成报告.我要达到的效果是,我希望我的应用程序生成特定月份的销售报告,例如,我希望它显示仅在5月份进行的销售.如果用户输入日期参数​​(例如2011年5月1日),则使用我拥有的代码,它将显示从2011年5月1日开始执行的所有记录,而不是仅生成may的记录.

我的代码如下所示

Hi guys,

I have a problem I’m producing an application that adds, read and manipulate data from a Sql Server database. The application also produces reports using a data parameter. The effect that I want to achieve is this, I want my application produce reports of sales that have been done for a particular month for example I want it to display the sales that were carried out in May only. With code that i have if a user inputs a date parameter for example 01-May-2011 it shows all of the records that carried out from 01-May-2011 onwards rather than producing the records for may only.

The code that I have is shown below

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Users\sim\Documents\Visual Studio 2008\Projects\Crystal Reports Date parameter\Crystal Reports Date parameter\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("Orderdate")
        crParameterValues = crParameterFieldDefinition.CurrentValues

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

        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()

    End Sub


是否可以在一个事件处理程序(单击事件)中使用多个参数,如果可以,我该如何做,以及如何解决我的问题.


Is it possible to use multiple parameters in one event handler (the click event) and if so how do i do it and also how do I over come my problem.

推荐答案

我对您的代码做了一些更改,现在看起来就像
I changed your code a bit and it now looks like
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Users\sim\Documents\Visual Studio 2008\Projects\Crystal Reports Date parameter\Crystal Reports Date parameter\CrystalReport1.rpt")
 
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As ParameterValues
        Dim crParameterDiscreteValue As ParameterDiscreteValue
 
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields

	' Begin parameter
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("Orderdate")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterDiscreteValue = New ParameterDiscreteValue
        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
	' End parameter

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



如果要添加更多参数,请在Begin parameterEnd parameter之间复制语句.然后更改参数名称和使用的值,它应该起作用.

至于显示从2011年5月1日开始的所有行,这与选择数据的方式有关.确保不仅检查Orderdate是否大于日期,还小于月末(在这种情况下,是2011年5月31日).



If you want to add more parameters copy statements between Begin parameter and End parameter. Then change the parameter name and the values used and it should work.

As for the fact that all line from 01-May-2011 and onwards are shown will have to do with how the data is selected. Make sure that you not only check if the Orderdate is larger than the date but also smaller than the end of the month (in this case 31-May-2011).


这篇关于水晶报表中的多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆