简体   繁体   中英

TextBox value from a form and display it to Crystal Reports using VB.NET

I created a parameter in Crystal Report named IID . But when the report loads it has nothing to display with.

This is my code :

Dim cryRpt As New rptPrntIss
cryRpt.Load("C:\Users\IEEC\Desktop\Sys\InventorySys\InventorySys\rptPrntIss.rpt")
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()

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

crParameterDiscreteValue.Value = frmInvntStocks.txtIID.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("IID")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()

You are assigning the report object to viewer and refreshing at two places. Assign the report object ( cryRpt ) to viewer ( CrystalReportViewer1 ) only in the last and remove refresh in the last too. Refresh is likely to drop all your modifications to the report object ie any filters, parameters etc. Modify your code as below:

cryRpt.Load("C:\Users\IEEC\Desktop\Sys\InventorySys\InventorySys\rptPrntIss.rpt")
'REMOVE REPORTSOURCE AND REFRESH STATEMENTS HERE
Dim crParameterFieldDefinitions As ParameterFieldDefinitions

and

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrystalReportViewer1.ReportSource = cryRpt
'REMOVE REFRESH HERE

Report Part Create A New Parameter 'TestParameter' on your report then put Your desire location.

VB.Net Part now Click on Project Menu and go Your Project Propertise and click Setting then setup this format

ÿ Private Sub btnShowReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowReport.Click Dim MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument = New DailyShadeCosting MyReport.SetParameterValue("TestParameter", TextBox6.Text) ShowReport(MyReport, filterstring, CrystalReportViewer1) End Sub Public Sub ShowReport(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal filterstring As String, ByVal CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer) Dim myLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo Dim myTable As Table For Each myTable In MyReport.Database.Tables myLogonInfo = myTable.LogOnInfo myLogonInfo.ConnectionInfo.ServerName = My.Settings.RptserverPath.ToString myLogonInfo.ConnectionInfo.DatabaseName = My.Settings.Database.ToString myLogonInfo.ConnectionInfo.UserID = My.Settings.DBUser.ToString myLogonInfo.ConnectionInfo.Password = My.Settings.DBPass.ToString myTable.ApplyLogOnInfo(myLogonInfo) Next myTable CrystalReportViewer.ReportSource = MyReport CrystalReportViewer.SelectionFormula = filterstring CrystalReportViewer.Refresh() End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM