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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interfacing a Crystal Report object with ASP

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
0
0
US
I found a message here where someone was having an ASP problem with Crystal Reports.

I will be required to create a Crystal Report template that needs to be incorporated into my ASP site.

Does anyone know how to setup such an interface? Examples would be great. I presume (note I didn't say assume!) that you would create a report object; provide external hooks to a database recordset; compile it into a .dll; register the .dll with Windows; and then do an ASP "Set crObject = CreateObject("CrystalReport.Application")".

Any help would be greatly appreciated. Thanks,
Jerry


Jerry Scannell
JerryScannell@cox.net or
JScannell@citystatecomputer.com
 
i am also looking for similar functionality in my Cold Fusion page. Pl.let me know if you found any solution for this.

Appriciate your help..

Thanks,
Rama Kommineni
ramkommineni@yahoo.com
 
Hi guy's

Take a look at Crystal Decision´s site for the file aspxmps8 and others. There are various examples there.

Jurandi

e-mail:
jurandi.nunes@itelefonica.com.br
 
here's an example page behind in vb. Having created your crystal report, add a crystal report viewer from your toolbox to an aspx page. hit the "view code" and paste something similar to this;

Code:
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

'Need these to run a Crystal Report
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

'-------------------------------
' use the class name that vs.net created here
Public Class Person_log_hits1
'-------------------------------
    Inherits System.Web.UI.Page
    Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer

'this function allows you to specify parameters for your 
'report - I found it elsewhere in C# and translated.
'very handy it is to..
    Sub SetReportParameter(ByVal report As ReportDocument, ByVal parameterName As String, ByVal parameterValue As Object)

        Dim crParamDef As ParameterFieldDefinition
        Dim currentValues As ParameterValues
        Dim paramValue As ParameterDiscreteValue
        paramValue = New ParameterDiscreteValue()

        crParamDef = report.DataDefinition.ParameterFields(parameterName)
        currentValues = crParamDef.CurrentValues
        paramValue.Value = parameterValue
        currentValues.Add(paramValue)

        crParamDef.ApplyCurrentValues(currentValues)
    End Sub

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    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()

'------------------------
'enter the physical root of the report. in c#, you have to 
'escape this (double \\ all over the shop)
'------------------------
        Dim oRpt As ReportDocument
        oRpt = New ReportDocument()
        oRpt.Load(&quot;c:\inetpub\[URL unfurl="true"]wwwroot\crdemo\document_hits\Person_log_hits.rpt&quot;)[/URL]

        Dim crTableLogOnInfo = New TableLogOnInfo()
        Dim crConnectionInfo = New ConnectionInfo()
        Dim crParameterFields = New ParameterFields()

        Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
        Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
        Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

'-------------------
' define the login credentials and apply to every table 
' used in the report.
'-------------------
        crConnectionInfo.ServerName = &quot;dbserver&quot;
        crConnectionInfo.DatabaseName = &quot;dbname&quot;
        crConnectionInfo.UserID = &quot;user&quot;
        crConnectionInfo.Password = &quot;password&quot;
        crDatabase = oRpt.Database
        crTables = crDatabase.Tables

        For Each crTable In crTables
            crTableLogOnInfo = crTable.LogOnInfo
            crTableLogOnInfo.ConnectionInfo = crConnectionInfo
            crTable.ApplyLogOnInfo(crTableLogOnInfo)
        Next

        CrystalReportViewer1.ReportSource = oRpt
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

End Class

there. a bit long-winded, but that's the template I use for all pages that include crystal reports. just edit the commented bits from there.

oh - here it is in C#

Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

//Need these to run a Crystal Report
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

namespace Extranet.Reports
{
	/// <summary>
	/// Summary description for WebForm3.
	/// </summary>
////////////////////
// Use the name vs.net gives you here, so it matches with 
// the aspx page..
///////////////////
	public class document_log_hits_person_graph1 : System.Web.UI.Page
	{
		//This is the report viewer control.
		protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;

///////////////////////////
// param adding func - thanks to whoever I nicked this off!
///////////////////////////
		private static void SetReportParameter(ReportDocument report, string parameterName, object parameterValue)
		{
			ParameterFieldDefinition crParamDef;
			ParameterValues currentValues;
			ParameterDiscreteValue paramValue = new ParameterDiscreteValue();

			crParamDef			= report.DataDefinition.ParameterFields[parameterName];
			currentValues		= crParamDef.CurrentValues;
			paramValue.Value	= parameterValue;
			currentValues.Add(paramValue);

			crParamDef.ApplyCurrentValues(currentValues);
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
				
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			
			//Create a new report object.
			ReportDocument crReportDocument	= new ReportDocument();
//////////////////////////////////
// escaped physical location
//////////////////////////////////
			crReportDocument.Load(&quot;C:\\Inetpub\\[URL unfurl="true"]wwwroot\\BluePrintStage\\Central\\Extranet\\Reports\\document_log_hits_person_graph.rpt&quot;);[/URL]
			
			//Create a logonInfo Structure 
			TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
			ConnectionInfo crConnectionInfo = new ConnectionInfo();
			
			//Crystal Report Properties
			CrystalDecisions.CrystalReports.Engine.Database crDatabase;
			CrystalDecisions.CrystalReports.Engine.Tables crTables;

			crConnectionInfo.ServerName		= &quot;dbserver&quot;;
			crConnectionInfo.DatabaseName	= &quot;dbname&quot;;
			crConnectionInfo.UserID			= &quot;user&quot;;
			crConnectionInfo.Password		= &quot;password&quot;;
			crDatabase						= crReportDocument.Database;
			crTables						= crDatabase.Tables;

			foreach(CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
			{
				crTableLogOnInfo = crTable.LogOnInfo;
				crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
				crTable.ApplyLogOnInfo(crTableLogOnInfo);
			}

			SetReportParameter(crReportDocument, &quot;dateStart&quot;, Request.QueryString[&quot;dateStart&quot;]);
		    SetReportParameter(crReportDocument, &quot;item_FKID&quot;, Request.QueryString[&quot;item_FKID&quot;]);
			CrystalReportViewer1.ReportSource		= crReportDocument;
			
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}


I really hope that ends up helping a load of people to save the time and stress that crystal in .net caused me...

--------------------------------------------------
- better than toast.
Penguins - better than --------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top