Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a Crystal Report that uses data sourced from 3 stored procedures in SQL Server. When I run the report via a WinForm it asks me for the parameters, even though I'm passing them through in the VB.Net code. Here's what I've got:

 

 

'Logon to the server

Dim crReport As New ContactReport()

Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

Dim crLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo()

ReportViewer.LogOnInfo = New CrystalDecisions.Shared.TableLogOnInfos()

crLogonInfo.TableName = "sp_CM_SelectContactForReport;1"

With crLogonInfo.ConnectionInfo

.ServerName = "(local)"

.DatabaseName = "ContactsManager"

.UserID = "xx" 'UserId

.Password = "xx" 'Password

End With

ReportViewer.LogOnInfo.Add(crLogonInfo)

 

'Create the parameter objects

Dim ParameterFields As New CrystalDecisions.Shared.ParameterFields()

Dim ParameterField As New CrystalDecisions.Shared.ParameterField()

Dim spValue As New CrystalDecisions.Shared.ParameterDiscreteValue()

 

'Add contact ID parameter

ParameterField.ParameterFieldName = "@cnt_ID"

ParameterField.ParameterType = CrystalDecisions.[shared].ParameterType.StoreProcedureParameter

spValue.Value = intRowID

ParameterField.CurrentValues.Add(spValue)

ParameterFields.Add(ParameterField)

 

'Add current user ID parameter

ParameterField.ParameterFieldName = "@cnt_UserID"

ParameterField.ParameterType = CrystalDecisions.[shared].ParameterType.StoreProcedureParameter

spValue.Value = strUserID

ParameterField.CurrentValues.Add(spValue)

ParameterFields.Add(ParameterField)

 

ReportViewer.ParameterFieldInfo = ParameterFields

 

'Show the report

ReportViewer.ReportSource = crReport

 

 

 

The code runs all the way through, appears to add the parameters, but when the report runs it comes up with the parameter entry dialog for both parameters... anyone know what I'm missing here?

 

TIA...

 

Mike.

Posted (edited)

Try using parameter field definitions since the parameters already exit in the report..

 

Also, I don't think you need the "@" symbol in front of the crystal reports parameters.

 

try..

 

Dim crParameterFieldDefinitions As ParameterFieldDefinitions = ReportViewer.DataDefinition.ParameterFields

Dim ParameterField As ParameterFieldDefinition = crParameterFieldDefinitions.Item("cnt_ID")

Dim crParameterValues As ParameterValues = crParameterFieldDefinition.CurrentValues

Dim spValue As New ParameterDiscreteValue()
spValue.Value = intRowID

crParameterValues.Add(spValue)
ParameterField.ApplyCurrentValues(crParameterValues)

 

for each parameter and see how that suits your fancy..

Edited by pcf108
Posted

Thanks for that - I did eventually work out that I needed to add FieldDefinition objects and cycle through each parameter setting them up.... just in case anyway else runs into this problem here's how I did it.

 

'Create the parameter objects

Dim crParamFieldDef As ParameterFieldDefinition

Dim crParamFieldDefs As ParameterFieldDefinitions

Dim crParamValues As New ParameterValues()

Dim crParamDiscreteValue As New ParameterDiscreteValue()

 

'Fetch the current report paramter definitions.

crParamFieldDefs = crReportDocument.DataDefinition.ParameterFields

 

For Each crParamFieldDef In crParamFieldDefs

If crParamFieldDef.ParameterType = ParameterType.StoreProcedureParameter And _

crParamFieldDef.IsLinked = False Then

 

Select Case crParamFieldDef.ValueType

Case FieldValueType.NumberField

crParamDiscreteValue.Value = Convert.ToInt32(intRowID)

crParamValues = crParamFieldDef.CurrentValues

crParamValues.Add(crParamDiscreteValue)

crParamFieldDef.ApplyCurrentValues(crParamValues)

 

Case Else

crParamDiscreteValue.Value = CStr(strUserID)

crParamValues = crParamFieldDef.CurrentValues

crParamValues.Add(crParamDiscreteValue)

crParamFieldDef.ApplyCurrentValues(crParamValues)

End Select

Else

'Item.SetCurrentValue Item.DefaultValue,Item.ValueType

End If

Next

 

Maybe this is the long way around the problem but it seems to work!

 

Cheers,

 

Mike.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...