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 April 12th, 2006, 02:19 AM
Authorized User
 
Join Date: Aug 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Subreport with formula selection

Hello,

  I am using teo subreports in one report and main report is not using any table, but both subreports areusing one table for each. I have to retrieve data from subreports using a selection criteria, here it's schoolid.
After defining the formula field like {TmpForm7A.SchoolID}={@SchoolID} in Crystal reports, I have tried 'subRepDoc.DataDefinition.FormulaFields("SchoolID" ).Text = "'" & SchoolID & "'"
' in asp.net,but it's showing no record selection, eventhough there is value for the particular school id I passed into the program. When I tried to print 'FormulaName ', it was giving {@SchoolID}, but the folowing code is not functing I think. Any suggection?

subRepDoc.DataDefinition.FormulaFields("SchoolID") .Text = "'" & SchoolID & "'"

Thanks
Ceema
My code is as follows...



  Dim Da As New SqlDataAdapter
        Dim Ds As New DataSet
        Dim Dai As New SqlDataAdapter
        Dim Dsi As New DataSet
        Dim SchoolID As String
        Dim ClassID As String
        SchoolID = "Ab1"
        crDatabase = repDoc.Database
        crTables = crDatabase.Tables


        Dim myConnection As SqlConnection
        For Each crTable In crTables
            With crConnInfo
                .ServerName = "IBRA"
                .DatabaseName = "FSchool"
                .UserID = "sa"
                .Password = "123"
            End With
            crLogOnInfo = crTable.LogOnInfo
            crLogOnInfo.ConnectionInfo = crConnInfo
            crTable.ApplyLogOnInfo(crLogOnInfo)


            If (crTable.TestConnectivity()) Then
                If (crTable.Location.IndexOf(".") > 0) Then
                    crTable.Location = crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
                Else

                    crTable.Location = crTable.Location
                End If


            Else

            End If

        Next

        crSections = repDoc.ReportDefinition.Sections

        For Each crSection In crSections
            crReportObjects = crSection.ReportObjects
            For Each crReportObject In crReportObjects
                If crReportObject.Kind = ReportObjectKind.SubreportObject Then


                    crSubreportObject = CType(crReportObject, SubreportObject)


                    subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject. SubreportName)
                    crDatabase = subRepDoc.Database
                    crTables = crDatabase.Tables
                    For Each crTable In crTables
                        With crConnInfo
                            .ServerName = "IBRA"
                            .DatabaseName = "FSchool"
                            .UserID = "sa"
                            .Password = "123"
                        End With
                        crLogOnInfo = crTable.LogOnInfo
                        crLogOnInfo.ConnectionInfo = crConnInfo
                        crTable.ApplyLogOnInfo(crLogOnInfo)
                        Dim thisFormulaField As CrystalDecisions.CrystalReports.Engine.FormulaFiel dDefinition
                            Select Case crSubreportObject.SubreportName
                                Case "Form7DetailsB.rpt"

                                '********Tried to pass parameter value like this
                                'subRepDoc.DataDefinition.FormulaFields("SchoolID" ).Text = "'" & SchoolID & "'"
'tried to print number of formulas
                                'Response.Write(repDoc.DataDefinition.FormulaField s.Count)


                                For Each thisFormulaField In repDoc.DataDefinition.FormulaFields
                                    ' Response.Write(thisFormulaField.FormulaName)

                                    If thisFormulaField.FormulaName = "{@SchoolID}" Then
                                        subRepDoc.DataDefinition.FormulaFields("SchoolID") .Text = "'" & SchoolID & "'"
                                        Response.Write(repDoc.DataDefinition.FormulaFields .Count)
                                    End If
                                Next
                                Response.Write("<br>")

                                Case "Form7DetailsA.rpt"


                                For Each thisFormulaField In repDoc.DataDefinition.FormulaFields

                                    If thisFormulaField.FormulaName = "{@SchoolID}" Then
                                        subRepDoc.DataDefinition.FormulaFields("SchoolID") .Text = "'" & SchoolID & "'"
                                        Response.Write(repDoc.DataDefinition.FormulaFields .Count)
                                    End If
                                Next

                            End Select
                        Next
                        If (crTable.TestConnectivity()) Then
                            If (crTable.Location.IndexOf(".") > 0) Then
                                crTable.Location = crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
                            Else
                                crTable.Location = crTable.Location
                            End If
                        Else

                        End If

                End If
            Next
        Next



        CrystalReportViewer1.ReportSource = repDoc



    End Sub
    Function FunMyCon() As SqlConnection
        Dim _ConStr As String
        Dim _Conn As SqlConnection
        _ConStr = ConfigurationSettings.AppSettings("MyDB")
        _Conn = New SqlConnection(_ConStr)
        _Conn.Open()
        Return _Conn
    End Function
 
Old April 12th, 2006, 02:41 AM
Authorized User
 
Join Date: Aug 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I have got the solution, I kept it like this

subRepDoc.DataDefinition.FormulaFields.Item("Schoo lID").Text = "'ab0'" and now it's working. The entire code I am pasting here, some one may find it useful later...



Imports System.Data
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data.SqlClient
Imports CrystalDecisions.Web.Design
Public Class testreport
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
    Dim crSections As Sections
    Dim crSection As Section
    Dim crReportObjects As ReportObjects
    Dim crReportObject As ReportObject
    Dim crSubreportObject As SubreportObject
    Dim crDatabase As Database
    Dim crTables As Tables
    Dim crTable As Table
    Dim crLogOnInfo As TableLogOnInfo
    Dim crConnInfo As New ConnectionInfo

    Dim repDoc As New Form7
    Dim subRepDoc As New ReportDocument
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration 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
        Dim Da As New SqlDataAdapter
        Dim Ds As New DataSet
        Dim Dai As New SqlDataAdapter
        Dim Dsi As New DataSet
        Dim SchoolID As String
        ' SchoolID = Session("SchoolID")
        Dim ClassID As String
        ' ClassID = Session("ClassID")
        SchoolID = "'Ab0'"
        crDatabase = repDoc.Database
        crTables = crDatabase.Tables


        Dim myConnection As SqlConnection
        For Each crTable In crTables
            With crConnInfo
                .ServerName = "IBRA"
                .DatabaseName = "FSchool"
                .UserID = "sa"
                .Password = "123"
            End With
            crLogOnInfo = crTable.LogOnInfo
            crLogOnInfo.ConnectionInfo = crConnInfo
            crTable.ApplyLogOnInfo(crLogOnInfo)


            If (crTable.TestConnectivity()) Then
                If (crTable.Location.IndexOf(".") > 0) Then
                    crTable.Location = crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
                Else

                    crTable.Location = crTable.Location
                End If


            Else

            End If

        Next

        crSections = repDoc.ReportDefinition.Sections

        For Each crSection In crSections
            crReportObjects = crSection.ReportObjects
            For Each crReportObject In crReportObjects
                If crReportObject.Kind = ReportObjectKind.SubreportObject Then


                    crSubreportObject = CType(crReportObject, SubreportObject)


                    subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject. SubreportName)
                    ' Response.Write(crSubreportObject.SubreportName)
                    'Response.Write("<br>")
                    crDatabase = subRepDoc.Database
                    crTables = crDatabase.Tables
                    For Each crTable In crTables
                        With crConnInfo
                            .ServerName = "IBRA"
                            .DatabaseName = "FSchool"
                            .UserID = "sa"
                            .Password = "123"
                        End With
                        crLogOnInfo = crTable.LogOnInfo
                        crLogOnInfo.ConnectionInfo = crConnInfo
                        crTable.ApplyLogOnInfo(crLogOnInfo)
                    Next
                    If (crTable.TestConnectivity()) Then
                        If (crTable.Location.IndexOf(".") > 0) Then
                            crTable.Location = crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
                        Else
                            crTable.Location = crTable.Location
                        End If
                    Else

                    End If

                     subRepDoc.DataDefinition.FormulaFields.Item("Schoo lID").Text = "'ab0'"
                    'subRepDoc.DataDefinition.FormulaFields.Item("Scho olID").Text = """ & SchoolID & """
                End If
            Next
        Next

    

        CrystalReportViewer1.ReportSource = repDoc



    End Sub
    Function FunMyCon() As SqlConnection
        Dim _ConStr As String
        Dim _Conn As SqlConnection
        _ConStr = ConfigurationSettings.AppSettings("MyDB")
        _Conn = New SqlConnection(_ConStr)
        _Conn.Open()
        Return _Conn
    End Function


End Class





Similar Threads
Thread Thread Starter Forum Replies Last Post
subreport srnarla Crystal Reports 1 August 31st, 2006 10:48 AM
link the subreport bib VB.NET 2002/2003 Basics 0 August 30th, 2006 06:38 AM
subreport bib Visual Basic 2005 Basics 0 August 25th, 2006 12:56 AM
Record selection formula and export to pdf sudarshan73 Crystal Reports 0 February 9th, 2006 12:00 PM
A subreport cannot contain a subreport. dkells Crystal Reports 0 March 3rd, 2005 06:05 PM





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