如何将txtbox值从表单传递到水晶报表并打印?

时间:2016-09-05 14:40:58

标签: c# visual-studio-2010 crystal-reports

我有一个“创建检查表单”,其中包含文本框和日期时间选择器。在form1(CreateCheckForm)中,用户将填充文本框Payee, Amount_in_Figuredate,这些文本框将在填写这些文本框后单击btnButton后打印出来。现在,我希望将文本框值传递到我的其他表单中,并使用水晶报表,这样我就可以打印它而不将其保存到数据库,但每当我点击按钮时,我的水晶报表中都没有显示任何内容。只是一个空白页面..下面是我的代码:

这是带有水晶报表(form2)的表单背后的代码:

    Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
    Dim Report1 As New CrystalReport1

        Report1.SetParameterValue("amtinwords", frmCreateCheckURC.txtAmtInWords.Text)
        CrystalReportViewer1.ReportSource = Report1
Report1.SetParameterValue("issuedate", frmCreateCheckURC.dtpDate.Text)
        CrystalReportViewer1.ReportSource = Report1
Report1.SetParameterValue("?amtinfigure", frmCreateCheckURC.txtAmtInWords.Text)
        CrystalReportViewer1.ReportSource = Report1
Report1.SetParameterValue("?payee", frmCreateCheckURC.txtAmtInWords.Text)
        CrystalReportViewer1.ReportSource = Report1
    End Sub

参数名称为amtinwords,issuedate,amtinfigure,amtinwords,payee

2 个答案:

答案 0 :(得分:2)

尝试以下代码将数据从form1传递到form2,然后尝试使用您的代码将数据传递到crystal report

Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim sTitle As String
    Dim sText As String
    sTitle = TextBox1.Text
    sText = TextBox2.Text
    Dim frm As New Form2(sTitle, sText)
    frm.Show()
End Sub

<强>窗体2

Public Sub New(ByVal sTitle As String, ByVal sText As String)
    InitializeComponent()
    Me.Text = sTitle
    Me.Label1.Text = sText
End Sub

答案 1 :(得分:0)

我能够解决我的问题。唯一的问题是我将代码发布在错误的地方和表单上。代码应该在btnButton中。