Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
|
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2006, 09:39 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default CrystalReport.net VisualStudio 2005 ASP.net (VB)

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?





Similar Threads
Thread Thread Starter Forum Replies Last Post
autocomplete dropdownlistASP.NET 2.0 & VB.NET 2005 alexdcosta ASP.NET 2.0 Professional 10 May 11th, 2009 02:21 AM
using .net framework 2.0 with vb.net 2005 vb1720 .NET Framework 2.0 1 July 28th, 2007 04:47 PM
Conversion from .Net 2003 to .Net 2005 using VB.Ne coleenh Visual Basic 2005 Basics 0 September 19th, 2006 02:48 PM
Can I run VB .net 2005 with DOT NET 2003 APPLICATI kadesskade BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 August 8th, 2006 05:14 AM
send MASS Emails in ASP.NET 2 with VB.NET 2005 alexdcosta ASP.NET 2.0 Basics 1 July 17th, 2006 12:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.