Figures

Figure 2 Logging Crystal Reports onto the Database
  Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
For Each tbCurrent In cbsMain.Database.Tables
    tliCurrent = tbCurrent.LogOnInfo
    With tliCurrent.ConnectionInfo
        .ServerName = "localhost"
        .UserID = "ReportUser"
        .Password = "msdn"
        .DatabaseName = "Northwind"
    End With
    tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent

Figure 6 Creating a Stored Procedure

Figure 6 Creating a Stored Procedure
Figure 7 Modified OnLoad Event
  Private Sub frmViewReport_Load(ByVal sender As Object, ByVal e As _
  System.EventArgs) Handles MyBase.Load
    Dim scmCustomersSP As New SqlClient.SqlCommand("spCustomers", _
      scnNorthwind)
    scmCustomersSP.CommandType = CommandType.StoredProcedure
    scmCustomersSP.Parameters.Add("@CustPattern", "A")
    Dim sdaCustomersSP As New SqlClient.SqlDataAdapter(scmCustomersSP)
    Dim dsReport As New DataSet()
    sdaCustomersSP.Fill(dsReport, "Customers")
    cbsMain.SetDataSource(dsReport)
    cvwMain.ReportSource = cbsMain
End Sub

Figure 9 Assigning Parameters
  Private Sub frmViewReport_Load(ByVal sender As Object, ByVal e As _
  System.EventArgs) Handles MyBase.Load
    Dim pvCustPattern As New CrystalDecisions.Shared.ParameterValues()
    Dim pdvCustPattern As New _
      CrystalDecisions.Shared.ParameterDiscreteValue()
    pdvCustPattern.Value = "A"
    pvCustPattern.Add(pdvCustPattern)
    cbsMain.DataDefinition.ParameterFields _
      ("@CustPattern").ApplyCurrentValues(pvCustPattern)
    cvwMain.ReportSource = cbsMain
End Sub

Figure 10 MTS

Figure 10 MTS
Figure 12 Implementing ICachedReport in a Component Class
  Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Imports System
Imports System.ComponentModel
Public Class cMSDNCachedReport
    Inherits Component
    Implements ICachedReport
    'Required by the Component Designer
    Private components As System.ComponentModel.Container
    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub _
      InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub
    Public ASPRequest As Web.HttpRequest
    Public Sub New()
        MyBase.New()
    End Sub
    Public Overridable Property IsCacheable() As [Boolean] Implements _
      CrystalDecisions.ReportSource.ICachedReport.IsCacheable
        Get
            Return True
        End Get
        Set(ByVal Value As [Boolean])
            '
        End Set
    End Property
    Public Overridable Property ShareDBLogonInfo() As [Boolean] Implements _
      CrystalDecisions.ReportSource.ICachedReport.ShareDBLogonInfo
        Get
            Return False
        End Get
        Set(ByVal Value As [Boolean])
            '
        End Set
    End Property
    Public Overridable Property CacheTimeOut() As TimeSpan Implements _
      CrystalDecisions.ReportSource.ICachedReport.CacheTimeOut
        Get
            Return CachedReportConstants.DEFAULT_TIMEOUT
        End Get
        Set(ByVal Value As TimeSpan)
            '
        End Set
    End Property
    Public Overridable Function CreateReport() As  _
      CrystalDecisions.CrystalReports.Engine.ReportDocument Implements _
      CrystalDecisions.ReportSource.ICachedReport.CreateReport
        Dim rpt As CustomersBasic = New CustomersBasic()
        Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
        Dim pvCustPattern As New CrystalDecisions.Shared.ParameterValues()
        Dim pdvCustPattern As New _
          CrystalDecisions.Shared.ParameterDiscreteValue()
        pdvCustPattern.Value = IIf(ASPRequest("ParamValue") Is Nothing, _
          "", ASPRequest("ParamValue"))
        pvCustPattern.Add(pdvCustPattern)
        rpt.DataDefinition.ParameterFields _
          ("@CustPattern").ApplyCurrentValues(pvCustPattern)
        For Each tbCurrent In rpt.Database.Tables
            Dim oLIInfo As CrystalDecisions.Shared.TableLogOnInfo
            oLIInfo = tbCurrent.LogOnInfo
            With oLIInfo.ConnectionInfo
                .ServerName = "localhost"
                .UserID = "ReportUser"
                .Password = "msdn"
                .DatabaseName = "Northwind"
            End With
            tbCurrent.ApplyLogOnInfo(oLIInfo)
        Next tbCurrent
        rpt.Site = Me.Site
        Return rpt
    End Function
    Public Overridable Function GetCustomizedCacheKey(ByVal request _
      As RequestContext) As [String] Implements _
      CrystalDecisions.ReportSource.ICachedReport.GetCustomizedCacheKey
        Dim key As [String] = Nothing
        '// The following is the code used to generate the default
        '// cache key for caching report jobs in the ASP.NET Cache.
        '// Feel free to modify this code to suit your needs.
        '// Returning key == null causes the default cache key to
        '// be generated.
        key = RequestContext.BuildCompleteCacheKey( _
            request, _
            Nothing, _
            Me.GetType(), _
            Me.ShareDBLogonInfo)
        key &= IIf(ASPRequest("ParamValue") Is Nothing, _
          "", ASPRequest("ParamValue"))
        Return key
    End Function
End Class

Figure 13 Exporting a Report to PDF
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
  System.EventArgs) Handles MyBase.Load
    Dim dfdoCustomers As New _
      CrystalDecisions.Shared.DiskFileDestinationOptions()
    Dim szFileName As String = "c:\windows\temp\myreport2.pdf"
    dfdoCustomers.DiskFileName = szFileName
    With cbsMain
        .ExportOptions.ExportDestinationType = _
          CrystalDecisions.Shared.ExportDestinationType.DiskFile
        .ExportOptions.ExportFormatType = _
          CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
        .ExportOptions.DestinationOptions = dfdoCustomers
        .Export()
    End With
    Response.Redirect(szFileName)
End Sub