vb.net 如何在 Visual Basic 2005 中的水晶报表中将文本框值作为参数传递
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17635721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass textbox values as parameter in crystal report in Visual Basic 2005
提问by iGNRev
Form1
has a button1
and a texbox1
, when I click button1
, form2
will load with crystal report on it and display data that I put on textbox1
. Already created Parameters Field crTextBox
and put into crystalreport. How can I pass textbox1.text
value to crTextBox
.
Form1
有一个button1
和一个texbox1
,当我点击时button1
,form2
会在上面加载水晶报告并显示我放上的数据textbox1
。已经创建了参数字段crTextBox
并放入了 Crystalreport。如何将textbox1.text
值传递给crTextBox
.
回答by David -
Add the following code inside Form2
在 Form2 中添加以下代码
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim Report1 As New CrystalReport1
Report1.SetParameterValue("crTextBox", Form1.TextBox1.Text)
CrystalReportViewer1.ReportSource = Report1
End Sub
回答by Denn
You have to use a parameter fields of Crystal report for this....
您必须为此使用Crystal 报表的参数字段....
1.Open Field Explorer window in Crystal report.
1.在水晶报表中打开字段资源管理器窗口。
2.Go to Parameter Fields.
2.转到参数字段。
3.Right Click on "Parameter Fields" Click on "New"
3.右键单击“参数字段”单击“新建”
4.In the pop-up window give a Name for your parameter and give its Data Type.Name is mytextBoxValue and Data Type is String.
4.在弹出窗口中为您的参数指定一个名称并指定其数据类型。名称为 mytextBoxValue,数据类型为字符串。
5.A parameter field[mytextBoxValue] will be added under Parameter Fields...Drag this field to your report and place where you want to show your textbox value.
5.A 参数字段[mytextBoxValue] 将被添加到参数字段下...将该字段拖到您的报告中并放置在您要显示文本框值的位置。
6.Now in the code behind file write the following code to pass your TextBox value to this Crystal report parameter field.
6.现在在代码隐藏文件中编写以下代码以将您的 TextBox 值传递给此 Crystal 报表参数字段。
Dim txtValue As String=TextBox1.Text
Dim txtValue As String=TextBox1.Text
Dim myReport As New CrystalReport1
将 myReport 调暗为新 CrystalReport1
myReport .SetParameterValue("mytextBoxValue", txtValue )
myReport .SetParameterValue("mytextBoxValue", txtValue )
回答by Federico Luna
'this code works fine for me
Dim CrxReport As New cm_Detallado_Partes_vs
Try
Cursor.Current = Cursors.WaitCursor
CrystalReportViewer1.ReportSource = CrxReport
'the formula must be the same as it is used in CR
CrxReport.DataDefinition.RecordSelectionFormula = "{tpresupuesto.codigo} = '18-0004'"
CrystalReportViewer1.ShowExportButton = True
CrystalReportViewer1.ShowPrintButton = True
CrystalReportViewer1.ShowGroupTreeButton = True
CrystalReportViewer1.Zoom(100)
Cursor.Current = Cursors.Default
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
End Try
回答by Esselans
You should write something like:
你应该这样写:
Dim rpt as New ReportDocument
'rpt.Load("file.rpt") ...
'rpt.SetDatasource() ...
rpt.DataDefinition.FormulaFields.Item("MyFormula").Text = textbox1.text