I am new to Crystal Report. I am using VB.NET and Crystal Report 8.5
I created a report, when connecting to the database, I only see tables but not store procedures, I have all the access rights but the store procedures not show up in the wizards. Any way, I just select the table name Fabric and field names.
I want to display only one record, I look at show sql statement:
SELECT "Fabric"."FabricID", "Fabric"."CustomerID", "Fabric"."FabricCode", "Fabric"."SMProjectName", "Fabric"."SMPlanID", "Fabric"."SMRoomName", "Fabric"."SupplierName", "Fabric"."PatternAndColor"
, "Fabric"."QtyReceived", "Fabric"."DocumentID"
FROM "enterprise"."dbo"."Fabric
" "Fabric"
WHERE "Fabric"."FabricID"=222049
The FabricID need to be a parameter field. So I insert a "Record Selection Formula" and name the field "fabricParam" and it formula was {Fabric.FabricID} = 222049.
My Webform1.aspx.vb code is:
Imports CrystalDecisions.CrystalRe
ports.Engi
ne
Imports CrystalDecisions.Shared
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
erStepThro
ugh()> Private Sub InitializeComponent()
End Sub
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.Cryst
alReportVi
ewer
'Dim crpt As CrystalReport1
Dim crpt As crFabricLabel
Dim myTable As CrystalDecisions.CrystalRe
ports.Engi
ne.Table
Dim myLogin As CrystalDecisions.Shared.Ta
bleLogOnIn
fo
Private designerPlaceholderDeclara
tion As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'crpt = New CrystalReport1
crpt = New crFabricLabel
For Each myTable In crpt.Database.Tables
myLogin = myTable.LogOnInfo
myLogin.ConnectionInfo.Pas
sword = "pwd"
myLogin.ConnectionInfo.Use
rID = "user"
myTable.ApplyLogOnInfo(myL
ogin)
Next
Dim crParameterFieldDefinition
s As ParameterFieldDefinitions
Dim crParameterFieldDefinition
As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
'Set discrete value
crParameterDiscreteValue.V
alue = CInt("1000002442")
'Access first parameter field definition
crParameterFieldDefinition
s = crpt.DataDefinition.Parame
terFields
crParameterFieldDefinition
= crParameterFieldDefinition
s.Item("fa
bricParam"
)
' Add parameter value
crParameterValues = crParameterFieldDefinition
.CurrentVa
lues
crParameterValues.Add(crPa
rameterDis
creteValue
)
' Apply the current value to the parameter definition
crParameterFieldDefinition
.ApplyCurr
entValues(
crParamete
rValues)
CrystalReportViewer1.Repor
tSource = crpt
End Sub
End Class
When run the web form I got this error:
Exception Details: CrystalDecisions.CrystalRe
ports.Engi
ne.Invalid
ArgumentEx
ception: Invalid field name.
Source Error:
Line 51: 'Access first parameter field definition
Line 52: crParameterFieldDefinition
s = crpt.DataDefinition.Parame
terFields
Line 53: crParameterFieldDefinition
= crParameterFieldDefinition
s.Item("fa
bricParam"
)
Line 54:
Line 55: ' Add parameter value
So can anybody help me how to put in a parameter field into the Crystal report form so that {Fabric.FabricID} = some variable instead of a pre-defined number.
The error message tell me that I have not define fabricParam anywhere in the form but It is there.
I will get to how to get store procedure, but that will be next.
Many thanks
Start Free Trial