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
Printable View
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
A control in VB?
I am working with Crystal Report and ASP.NET.
How I attach the report in ASP CrystalReportViewer..
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:
Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports System.IO Public Class ReportView 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 crReportDocument As New ReportDocument '+-----------+ '| FOR LOGIN | '+-----------+ Dim crDatabase As Database Dim crTables As Tables Dim crTable As Table Dim crTableLogOnInfo As TableLogOnInfo Dim crConnectionInfo As ConnectionInfo '+-------------------+ '| FOR THE PARAMETER | '+-------------------+ Dim crParameterFields As ParameterFields Dim crParameterField As ParameterField Dim crParameterValues As ParameterValues Dim crParameterDiscreteValue As ParameterDiscreteValue '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 'Response.Write("<DIV><TD><B>Please wait...</B></TD></DIV>") 'Response.Write(Space(256)) 'Response.Flush() 'Response.Flush() '+----------------------+ '| CHOOSE REPORT TO RUN | '+----------------------+ If Session("isCanine") = 0 Then crReportDocument.Load("C:\inetpub\wwwroot\APPLE\Reports\PurchaseOrder.RPT") Else crReportDocument.Load("C:\inetpub\wwwroot\APPLE\Reports\PurchaseOrderCanine.RPT") End If '+-----------------+ '| SQL SERVER INFO | '+-----------------+ crConnectionInfo = New ConnectionInfo With crConnectionInfo .ServerName = "XXX" .DatabaseName = "XXX" .UserID = "XXX" .Password = "XXX" End With '+--------------------------------------------------+ '| GET THE TABLES COLLECTION FROM THE REPORT OBJECT | '+--------------------------------------------------+ crDatabase = crReportDocument.Database crTables = crDatabase.Tables '+-------------------------+ '| APPLY LOGIN INFORMATION | '+-------------------------+ For Each crTable In crTables crTableLogOnInfo = crTable.LogOnInfo crTableLogOnInfo.ConnectionInfo = crConnectionInfo crTable.ApplyLogOnInfo(crTableLogOnInfo) Next '+-------------+ '| VIEW REPORT | '+-------------+ CrystalReportViewer1.ReportSource = crReportDocument '+-----------------+ '| APPLY PARAMETER | '+-----------------+ crParameterFields = CrystalReportViewer1.ParameterFieldInfo crParameterField = crParameterFields.Item("@PONumber") crParameterValues = crParameterField.CurrentValues crParameterDiscreteValue = New ParameterDiscreteValue crParameterDiscreteValue.Value = Session("PONumber") crParameterValues.Add(crParameterDiscreteValue) CrystalReportViewer1.ParameterFieldInfo = crParameterFields End Sub End Class
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