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

Getting Crystal to work..?

Status
Not open for further replies.

kenjoswe

Technical User
Sep 19, 2000
327
SE
Hi all,

How can I get CrystalViewer to bind with something like?:

mySqlDA(strConn,strSQL)
mySqlDA.Fill(myDS)
CrystalReportViewer1.DataBind()

Where do I define the report to be displayed?

/Kent J.
 
It depends on how you set up your report.

First I create the report from a stored proc in SQL and save it w/out the data.

Here is a snipit of code I use to run it from .NET:
' To be able to get the values in web.config
Dim MachineType As String = System.Environment.GetEnvironmentVariable("MachineType")

' Load the selected report
Dim crReportDocument As New ReportDocument()

Dim sbPath As New System.Text.StringBuilder()
sbPath.Append(System.Configuration.ConfigurationSettings.GetConfig(MachineType)("DatabasePhysicalPath"))
sbPath.Append(System.Configuration.ConfigurationSettings.GetConfig(MachineType)("CrystalFilesLocation"))
sbPath.Append(_strFileName)

'Load the Report
Dim ErrorHandling As New ErrorHandlingUtils()
Try
crReportDocument.Load(sbPath.ToString)
Catch exc As System.Exception
Dim sourcepage As PageBase = CType(context.Handler, PageBase)
ErrorHandling.SendToErrorPage(Me, exc, REDIRECT_PAGE, sourcepage)
Finally
ErrorHandling = Nothing
End Try

' Get the logon information from web.config
Dim crConnectionInfo As New ConnectionInfo()
crConnectionInfo.ServerName = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportServerName")
crConnectionInfo.DatabaseName = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportDatabaseName")
crConnectionInfo.UserID = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportUserID")
crConnectionInfo.Password = System.Configuration.ConfigurationSettings.GetConfig(MachineType)("ReportPassword")

' Get the tables collection from the report object to apply logon information
Dim crDatabase As Database = crReportDocument.Database
Dim crTables As Tables = crDatabase.Tables

' Apply the logon information to each table in the collection
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim crTableLogonInfo As TableLogOnInfo
For Each crTable In crTables
crTableLogonInfo = crTable.LogOnInfo
crTableLogonInfo.ConnectionInfo = crConnectionInfo
crTableLogonInfo.TableName = crTable.Name
crTable.ApplyLogOnInfo(crTableLogonInfo)
crTable.Location = crTable.Name
Next

' Get the collection of parameters from previous page
Dim arParms As SqlClient.SqlParameter()
If Not Page.IsPostBack Then
arParms = sourcepage.CrystalParams
Session("ParamsCollection") = arParms
Else
arParms = Session("ParamsCollection")
End If

' Apply the parameters to the report document
RetrieveInitialRptParams(arParms, crReportDocument.DataDefinition.ParameterFields)

' Make the report the source for the viewer
crvReport.ReportSource = crReportDocument
 
NatGreen,

My report is CrystalReport1
This is what I have tired:

Dim crReport1 As CrystalReport1
InitializeComponent()
CrystalReportViewer1.DataBind()
crReport1.Load()
CrystalReportViewer1.ReportSource = crReport1

Where have I got it wrong?

/Kent J.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top