I have a web report that requires two parameters (a date range, and a string containing the start & end dates in the date range). I want to pass a hardcoded login, and two user selected parameters to this report (web based). When I use the crystalviewers smart tag feature I can pass the parameters but when I press the printer icon I am re-asked for the parameters and I never get the printer dialog. I am using SQL Server2K. I need to how do I pass the parameters to the report so that I can get the print function to work.
Update:
I solved my date range and sub-Title parameter problem by using three textboxes and modifying the
VB code behind code as follows:
Imports System.Collections
Imports System.Web.UI.WebControls
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Partial Class DateRangeRPT
Inherits System.Web.UI.Page
Private Const PARAMETER_FIELD1_NAME As String = "RPTDateRange"
Private Const PARAMETER_FIELD2_NAME As String = "RPTPeriod"
Private Const REPORT_NAME As String = "SelectRange.rpt"
Private myReport As ReportDocument
Dim reportPath As String = Server.MapPath("SelectRange.rpt")
Dim startDate As String
Dim endDate As String
Dim myRPTPeriod As String
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
ConfigureCrystalReports()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("myRPTPeriod").ToString.Length > 0 Then
Session("startDate") = RPTStartDate.Text
Session("endDate") = RPTEndDate.Text
Session("myRPTPeriod") = RPTPeriod.Text
ConfigureCrystalReports()
End If
End Sub
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
myReport.Dispose()
End Sub
Private Sub SetCurrentValuesForParameterField(ByVal myReport As ReportDocument, ByVal myRPTPeriod As String)
Dim currentParameterValues As ParameterValues = New ParameterValues()
Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
myParameterDiscreteValue.Value = RPTPeriod.Text
currentParameterValues.Add(myParameterDiscreteValu e)
Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReport.DataDefinition.ParameterFields
Dim myParameterFieldDefinition As ParameterFieldDefinition = myParameterFieldDefinitions(PARAMETER_FIELD2_NAME)
myParameterFieldDefinition.ApplyCurrentValues(curr entParameterValues)
End Sub
Private Function GetDateRangeValuesFromParameterField(ByVal myReport As ReportDocument) As String
Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReport.DataDefinition.ParameterFields
Dim myParameterFieldDefinition As ParameterFieldDefinition = myParameterFieldDefinitions(PARAMETER_FIELD2_NAME)
Dim defaultParameterValues As ParameterValues = myParameterFieldDefinition.DefaultValues
Dim myRPTPeriod As String
myRPTPeriod = "From " + RPTStartDate.Text + " Thru " + RPTEndDate.Text
Return myRPTPeriod
End Function
Private Sub SetDateRangeForRPT(ByVal myReport As ReportDocument, ByVal startDate As String, ByVal endDate As String)
Dim myParameterRangeValue As ParameterRangeValue = New ParameterRangeValue()
myParameterRangeValue.StartValue = startDate
myParameterRangeValue.EndValue = endDate
myParameterRangeValue.LowerBoundType = RangeBoundType.BoundInclusive
myParameterRangeValue.UpperBoundType = RangeBoundType.BoundInclusive
Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReport.DataDefinition.ParameterFields
Dim myParameterFieldDefinition As ParameterFieldDefinition = myParameterFieldDefinitions(PARAMETER_FIELD1_NAME)
myParameterFieldDefinition.CurrentValues.Clear()
myParameterFieldDefinition.CurrentValues.Add(myPar ameterRangeValue)
myParameterFieldDefinition.ApplyCurrentValues(myPa rameterFieldDefinition.CurrentValues)
End Sub
Protected Sub redisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles redisplay.Click
Session("startDate") = RPTStartDate.Text
Session("endDate") = RPTEndDate.Text
Session("myRPTPeriod") = RPTPeriod.Text
ConfigureCrystalReports()
End Sub
Private Sub ConfigureCrystalReports()
Dim reportPath As String = Server.MapPath("SelectRange.rpt")
myReport = New ReportDocument()
myReport.Load(reportPath)
Dim myDBConnectionInfo = New CrystalDecisions.Shared.ConnectionInfo()
With myDBConnectionInfo
.ServerName = "my server
.DatabaseName = "my SQL 2000 DB"
.UserId = "myUsderID"
.Password = "my Password"
End With
Dim myTableLogonInfo = New CrystalDecisions.Shared.TableLogOnInfo()
Dim myDatabase = myReport.Database()
Dim myTables = myDatabase.Tables()
Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
If Not IsPostBack Then
startDate = "4/1/2006"
endDate = "4/30/2006"
myRPTPeriod = "From " + startDate + " Thru " + endDate
Session("startDate") = startDate
Session("endDate") = endDate
Session("myRPTPeriod") = "From " + startDate + " Thru " + endDate
Else
startDate = Session("startDate")
endDate = Session("endDate")
myRPTPeriod = "From " + startDate + " Thru " + endDate
End If
For Each myTable In myTables
myTableLogonInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myDBConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
SetCurrentValuesForParameterField(myReport, myRPTPeriod)
SetDateRangeForRPT(myReport, startDate, endDate)
CrystalReportViewer1.ReportSource = myReport
End Sub
End Class
Any suggestions on how to improve this code?