Data Connectivity
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Data Connectivity
Message Icon Topic: Exporting To PDF in Crystal Report - No Data Post Reply Post New Topic
Author Message
lisackl
Newbie
Newbie
Avatar

Joined: 05 May 2007
Location: Malaysia
Online Status: Offline
Posts: 2
Quote lisackl Replybullet Topic: Exporting To PDF in Crystal Report - No Data
    Posted: 05 May 2007 at 9:15pm
Hi,
 
I'm having problem in exporting report with parameters to pdf. I had no problems at all on crystalreportviewer. Though pdf file is successfully created but no data is shown, it seems that it took the .rpt file from my source folder to convert into pdf.
 
How can I bind the pdf to my datasource?
 
Kindly help.
 
Below are my codes:
 
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class WebForm2
    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()
        Me.cachedtest31 = New treeview1.Cachedtest3
        '
        'cachedtest31
        '
        Me.cachedtest31.CacheTimeOut = System.TimeSpan.Parse("02:10:00")
        Me.cachedtest31.IsCacheable = True
        Me.cachedtest31.ShareDBLogonInfo = False
    End Sub
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
    Protected WithEvents cachedtest31 As treeview1.Cachedtest3
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    '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
        ' Declare variables needed to pass the parameters
        ' to the viewer control.
        'Put user code to initialize the page here
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      
        Dim paramField1 As New CrystalDecisions.Shared.ParameterField
        Dim paramField2 As New CrystalDecisions.Shared.ParameterField
        Dim paramFields As New CrystalDecisions.Shared.ParameterFields
        Dim discreteVal1 As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim discreteVal2 As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim rangeVal As New CrystalDecisions.Shared.ParameterRangeValue
        Dim crtableLogoninfos As New CrystalDecisions.Shared.TableLogOnInfos
        Dim crtableLogoninfo As New CrystalDecisions.Shared.TableLogOnInfo
        Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
        Dim CrTables As CrystalDecisions.CrystalReports.engine.Tables
        Dim CrTable As CrystalDecisions.CrystalReports.engine.Table
        Dim TableCounter
        Dim crReportDocument As New test3
        crReportDocument.Load()
        With crConnectionInfo
            .ServerName = "TCM-IT01\SQL"
            .DatabaseName = "SBODemo_US"
            .UserID = "sa"
            .Password = "Pass123"
        End With

        CrTables = crReportDocument.Database.Tables()
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next
        ' Set the name of the parameter field, this must match a
        ' parameter in the report.
        paramField1.ParameterFieldName = "ItemCode"
        discreteVal1.Value = TextBox1.Text
        paramField1.CurrentValues.Add(discreteVal1)
        paramField2.ParameterFieldName = "ItemCodeT"
        discreteVal2.Value = TextBox2.Text
        paramField2.CurrentValues.Add(discreteVal2)
        ' Add the parameter to the parameter fields collection.
        paramFields.Add(paramField1)
        paramFields.Add(paramField2)
        ' Set the parameter fields collection into the viewer control.
        CrystalReportViewer1.ParameterFieldInfo = paramFields
        CrystalReportViewer1.DisplayGroupTree = False
        CrystalReportViewer1.SeparatePages = False
        CrystalReportViewer1.ReportSource = crReportDocument
        Dim myExportOptions As ExportOptions
        myExportOptions = crReportDocument.ExportOptions
        Dim crDiskFileDestinationOptions = New DiskFileDestinationOptions
        crDiskFileDestinationOptions.DiskFileName = "c:\temp\item.pdf"
        myExportOptions = crReportDocument.ExportOptions
        With myExportOptions
            .DestinationOptions = crDiskFileDestinationOptions
            .ExportDestinationType = ExportDestinationType.DiskFile
            .ExportFormatType = ExportFormatType.PortableDocFormat
        End With
        Try
            crReportDocument.Export()
        Catch err As Exception
            'messagebox.Show(err.ToString())
        End Try
        Dim oStream As New IO.MemoryStream()
            oStream = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat)
            Response.Clear()
            Response.Buffer = True
            Response.ContentType = "application/pdf"
            Response.WriteFile("c:\temp\items.pdf")
            Response.Flush()
            Response.Close()
    End Sub

End Class
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 05 May 2007 at 10:09pm
I've seen comments on the BOBJ site about bugs relating to PDF exports missing data when passing parameters in code. Have you been to their support site to download the latest service packs? I would try that.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
lisackl
Newbie
Newbie
Avatar

Joined: 05 May 2007
Location: Malaysia
Online Status: Offline
Posts: 2
Quote lisackl Replybullet Posted: 08 May 2007 at 2:42am

Hi BrianBischof,

 
Finally i know what i had been missing so far... add in line below for each parameter field accordingly and everything will be running fine.

crReportDocument.SetParameterValue("SupCode", TextBox1.Text)

Thanks anyway. :)
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.027 seconds.