Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.Net page not passing variables to sub report in crystal

Status
Not open for further replies.

Modica82

Technical User
Jan 31, 2003
410
GB
Hi,

I have a crystal report that contains several sub reports. Now within the crystal reports IDE the report works correctly and all sub reports are generated and variables that were entered into the first main report are persisted to the sub reports. When i generate the report from my ASP.Net page and generate the report as a PDF, some of the sub reports get generated while 2 of them do not, and when i profile it in SQL it is as if the variables are not being passed to the sub report??? it did work a little while ago, so i am quite unsure how this has happened????

my code is:

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Load Report
        cr.Load(ConfigurationSettings.AppSettings("report"))

        'Perform Crystal Reports Login
        DoCRLogin(cr)

        'Pass Parameters and Set Report Source
        cr.SetParameterValue("jobcode", Request.Params("JobCode"))
        'cr.SetParameterValue("dateFrom", CDate(Request.Params("dFrom")))
        'cr.SetParameterValue("dateTo", CDate(Request.Params("dTo")))
        'cr.SetParameterValue("DateFrom2", CDate(Request.Params("dFrom2")))
        'cr.SetParameterValue("DateTo2", CDate(Request.Params("dTo2")))
        cr.SetParameterValue("dateFrom", CDate("02/01/2006"))
        cr.SetParameterValue("dateTo", CDate("02/07/2006"))
        cr.SetParameterValue("DateFrom2", CDate("03/07/2006"))
        cr.SetParameterValue("DateTo2", CDate("31/12/2006"))
        cr.SetParameterValue("FullPeriodStart", CDate(Request.Params("dFrom")))
        cr.SetParameterValue("FullPeriodEnd", CDate(Request.Params("dTo2")))
        cr.SetParameterValue("@Section1", 1)
        cr.SetParameterValue("@Section2", 2)
        cr.SetParameterValue("Currency", "£")

        ExportReport()
    End Sub

    Public Sub DoCRLogin(ByRef oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
        Dim _applyLogin As New ApplyCRLogin

        ' use ApplyLogin object to apply login info to all tables in CR object
        _applyLogin._dbName = ConfigurationSettings.AppSettings("dbName")
        _applyLogin._passWord = ConfigurationSettings.AppSettings("password")
        _applyLogin._serverName = ConfigurationSettings.AppSettings("servername")
        _applyLogin._userID = ConfigurationSettings.AppSettings("userid")
        _applyLogin.ApplyInfo(oRpt)

        ' clean up
        _applyLogin = Nothing

    End Sub

    Sub ExportReport()

        Dim oStream As New MemoryStream ' // using System.IO

        ' Select Case format
        '      Case "PDF"
        oStream = cr.ExportToStream( _
                    CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
        Response.ClearContent()
        Response.ClearHeaders()
        Response.Buffer = True
        Response.ContentType = "application/pdf"
        '--------------------------------------------------------------

        Try
            Response.BinaryWrite(oStream.ToArray())
            Response.Flush()
            Response.Close()
        Catch err As Exception
            Response.Write("< BR >")
            Response.Write(err.Message.ToString)
        End Try
    End Sub

Has anyone got an ideas??

THanks Rob

---------------------------------------
 
You might want to post this to the Crystal Reports Integrate forum. Off the top of my you may need to set the datasource information for each sub report. I do this in CR 9 for .net by:

crSections = crRepDoc.ReportDefinition.Sections
For Each crSection In crSections
crRepObjs = crSection.ReportObjects
For Each crRepObj In crRepObjs
If crRepObj.Kind = ReportObjectKind.SubreportObject Then
crSubRepObj = CType(crRepObj, SubreportObject)
Try
crSubRepDoc = crSubRepObj.OpenSubreport(crSubRepObj.SubreportName)
Catch engEx As OutOfLicenseException
CrystalErrorMessage = "Currently all of the available Crystal Reports Licenses are in use. Please wait a moment and try again."
WriteToReportLog(CrystalEventID, CrystalReportName, "Error Creating SubReport", engEX.Message)
Exit Sub
Catch engEx As EngineException
CrystalErrorMessage = engEx.Message
WriteToReportLog(CrystalEventID, CrystalReportName, "Error Creating SubReport", engEX.Message)
Exit Sub
End Try
crDatabase = crSubRepDoc.Database
crTables = crDatabase.Tables
For Each crTable In crTables
With crConnInfo
If UseRptServer = True And ReportingServerOnline Then
.ServerName = ConfigurationSettings.AppSettings("ReportServerName")
.DatabaseName = ConfigurationSettings.AppSettings("ReportDatabaseName")
.UserID = ConfigurationSettings.AppSettings("ReportUserID")
.Password = ConfigurationSettings.AppSettings("ReportPassWord")
Else
.ServerName = ConfigurationSettings.AppSettings("OLEDBServerName")
.DatabaseName = ConfigurationSettings.AppSettings("OLEDBDatabaseName")
.UserID = ConfigurationSettings.AppSettings("OLEDBUserID")
.Password = ConfigurationSettings.AppSettings("OLEDBPassWord")
End If
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
 
Hi,

the problem was somehow down to my stored procedure. Although it ran and returned data, the ASP.Net PDF generator did not like it, had a little play around and if worked, but i cant for the life of me understand what i changed as the code looks exactly the same.

Rob

---------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top