Results 1 to 5 of 5

Thread: Attaching Report to Crystal Report Viewer Control

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    17

    Unhappy Attaching Report to Crystal Report Viewer Control

    What steps should i follow to attach a report to crystal report viewer control?
    What lines of code i've to add and where??

    Looking forward..
    thnx in advance

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Attaching Report to Crystal Report Viewer Control

    A control in VB?
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    17

    Re: Attaching Report to Crystal Report Viewer Control

    I am working with Crystal Report and ASP.NET.
    How I attach the report in ASP CrystalReportViewer..

  4. #4
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381

    Re: Attaching Report to Crystal Report Viewer Control

    I use SQL SPROCs to populate my report but it should be closely the same on how you generate your report with ASP.NET.

    I design my report using the Crystal Software (Ver 9) and just call them inside my web pages.

    Create a web page and insert a CrystalReportViewer web control. Then add as needed the code below (report below has 1 parameter).
    VB Code:
    1. Imports CrystalDecisions.CrystalReports.Engine
    2. Imports CrystalDecisions.Shared
    3. Imports System.IO
    4.  
    5.  
    6. Public Class ReportView
    7.     Inherits System.Web.UI.Page
    8.  
    9. #Region " Web Form Designer Generated Code "
    10.  
    11.     'This call is required by the Web Form Designer.
    12.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    13.  
    14.     End Sub
    15.     Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
    16.     Dim crReportDocument As New ReportDocument
    17.     '+-----------+
    18.     '| FOR LOGIN |
    19.     '+-----------+
    20.     Dim crDatabase As Database
    21.     Dim crTables As Tables
    22.     Dim crTable As Table
    23.     Dim crTableLogOnInfo As TableLogOnInfo
    24.     Dim crConnectionInfo As ConnectionInfo
    25.  
    26.     '+-------------------+
    27.     '| FOR THE PARAMETER |
    28.     '+-------------------+
    29.     Dim crParameterFields As ParameterFields
    30.     Dim crParameterField As ParameterField
    31.     Dim crParameterValues As ParameterValues
    32.     Dim crParameterDiscreteValue As ParameterDiscreteValue
    33.  
    34.     'NOTE: The following placeholder declaration is required by the Web Form Designer.
    35.     'Do not delete or move it.
    36.     Private designerPlaceholderDeclaration As System.Object
    37.  
    38.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    39.         'CODEGEN: This method call is required by the Web Form Designer
    40.         'Do not modify it using the code editor.
    41.         InitializeComponent()
    42.     End Sub
    43.  
    44. #End Region
    45.  
    46.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    47.         'Response.Write("<DIV><TD><B>Please wait...</B></TD></DIV>")
    48.         'Response.Write(Space(256))
    49.         'Response.Flush()
    50.         'Response.Flush()
    51.  
    52.     '+----------------------+
    53.     '| CHOOSE REPORT TO RUN |
    54.     '+----------------------+  
    55.         If Session("isCanine") = 0 Then
    56.             crReportDocument.Load("C:\inetpub\wwwroot\APPLE\Reports\PurchaseOrder.RPT")
    57.         Else
    58.             crReportDocument.Load("C:\inetpub\wwwroot\APPLE\Reports\PurchaseOrderCanine.RPT")
    59.         End If
    60.         '+-----------------+
    61.         '| SQL SERVER INFO |
    62.         '+-----------------+
    63.         crConnectionInfo = New ConnectionInfo
    64.         With crConnectionInfo
    65.             .ServerName = "XXX"
    66.             .DatabaseName = "XXX"
    67.             .UserID = "XXX"
    68.             .Password = "XXX"
    69.         End With
    70.         '+--------------------------------------------------+
    71.         '| GET THE TABLES COLLECTION FROM THE REPORT OBJECT |
    72.         '+--------------------------------------------------+
    73.         crDatabase = crReportDocument.Database
    74.         crTables = crDatabase.Tables
    75.         '+-------------------------+
    76.         '| APPLY LOGIN INFORMATION |
    77.         '+-------------------------+
    78.         For Each crTable In crTables
    79.             crTableLogOnInfo = crTable.LogOnInfo
    80.             crTableLogOnInfo.ConnectionInfo = crConnectionInfo
    81.             crTable.ApplyLogOnInfo(crTableLogOnInfo)
    82.         Next
    83.         '+-------------+
    84.         '| VIEW REPORT |
    85.         '+-------------+
    86.         CrystalReportViewer1.ReportSource = crReportDocument
    87.         '+-----------------+
    88.         '| APPLY PARAMETER |
    89.         '+-----------------+
    90.         crParameterFields = CrystalReportViewer1.ParameterFieldInfo
    91.         crParameterField = crParameterFields.Item("@PONumber")
    92.         crParameterValues = crParameterField.CurrentValues
    93.         crParameterDiscreteValue = New ParameterDiscreteValue
    94.         crParameterDiscreteValue.Value = Session("PONumber")
    95.         crParameterValues.Add(crParameterDiscreteValue)
    96.         CrystalReportViewer1.ParameterFieldInfo = crParameterFields
    97.     End Sub
    98.  
    99. End Class

  5. #5
    New Member
    Join Date
    Apr 2006
    Posts
    13

    Re: Attaching Report to Crystal Report Viewer Control

    Here is code that we struggled with to make subreports work with CR11 in a VS2005 vb.net environment. The CR white papers helped but were not very clear. We put the CrystalReportViewer on the invoke form with all the SQL adapters and data sets and just turn it visible/not visible. We did not put a Report Document object on the CrystalReportViewer. Hope it helps.

    Dim subreportname1 As String
    Dim subreportobject1 As SubreportObject
    Dim subreport1 As New ReportDocument
    DataSetRptDocketBase1.Clear()
    SqlRptDocketBase.Fill(DataSetRptDocketBase1)
    DataSetRptSubDocketDetail1.Clear()
    SqlRptSubDocketDetail.Fill(DataSetRptSubDocketDetail1)

    Dim myreport As RptDocketsShort = New RptDocketsShort
    subreportobject1 = myreport.ReportDefinition.ReportObjects.Item("ObjRptSubDocketDetail")
    ‘ This object name identifies the subreport object on the main report
    ' and must be entered in the main report designer
    subreportname1 = subreportobject1.SubreportName
    subreport1 = myreport.OpenSubreport(subreportname1)
    subreport1.SetDataSource(DataSetRptSubDocketDetail1)
    myreport.SetDataSource(DataSetRptDocketBase1)
    CrystalReportViewer1.ReportSource = myreport

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width