简体   繁体   中英

Error when passing text values as parameters to Crystal Report Formula field from VB.Net

I am trying to pass some text to a formula field in a Crystal Report.
Formula field name is txtShopName .
shopName is a variable and it has the value of "TORCH-MINIMALL". I use VB.net to view the report and pass the parameter value as follows. However, I get an error when trying to view the report. (Image attached)

What could be the reason?. Is there any specific way which I have to create the formula field in the report?.

Dim crepBill As New repBill
crepBill.SetDatabaseLogon("sa", dbPwd)
crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = shopName
crepBill.RecordSelectionFormula = "{TB_SALES.bill_no} ='" & "B000002" & "'"
CrystalReportViewer1.ReportSource = crepBill
CrystalReportViewer1.Zoom(100)
CrystalReportViewer1.Refresh()
CrystalReportViewer1.RefreshReport()

在此处输入图像描述

Following line sets the formula to TORCH-MINIMALL while it should be "TORCH-MINIMALL"

crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = shopName

To add the double quotes, change the code as follows:

crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = """" & shopName & """"

Or you could also use single qoutes, as Crystal Reports support both:

crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = "'" & shopName & "'"

If showing a text is the only purpose of the formula-field, then one can also use a parameter-field.
The value of a parameter-field can be set as follows:

crepBill.SetParameterValue("nameOfTheParameterField", shopName)

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