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!

Binding reports using VB.NET

Status
Not open for further replies.

inspi

Technical User
May 24, 2006
50
US
Hi, i'm new in this forum.....i've an issue regarding binding reports using vb.net so that end users can use those reports with out actually having crystal on their PC's. I have some reports which are run using a stored procedure for which I'm not able to bind the reports properly. Please help me regarding the code to successfully bind such reports.

Thank you
Inspi
 
If you are using Crystal Reports XI, then I have done something similar to this.

I started out by making a single .aspx page (called viewReport.aspx) for all crystal reports. This single page contains only the CR.net viewer (called 'crViewer').

This page has code that sets the viewer's report source equal to a Report object stored in a session variable.

This way, multiple Crystal Reports can be viewed from a single page.

I then created a class file called 'clsRpt.vb', that looks like this:
-----------------------------------
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Public Class clsRPT
Private crReportDocument As ReportDocument = New ReportDocument

Sub New(ByVal FilePath As String)
crReportDocument.Load(FilePath, OpenReportMethod.OpenReportByTempCopy)


Public Sub setReportDBLogon(ByVal S As String, ByVal DB As String, ByVal U As String, ByVal P As String)
Try
crReportDocument.DataSourceConnections.Item(0).SetConnection(S, DB, U, P)
Catch ex As Exception
End Try
End Sub
End Sub

Public ReadOnly Property Report() As ReportDocument
Get
Return crReportDocument
End Get
End Property

End Class
-----------------------------------

This is the crux of the .net reporting process for us. In this class, we create a class that will do the following:

1) Create a report object with a private report document
2) Allow the programmer to pass in the DB credentials (microsoft sql server)
3) Return the whole report using the Report() property (VERY important).


Next:
In about 10 separate web pages (one separate web page for each report), I use code that references the above class.

For example, if a user is trying to view report #7 (called "Report7.rpt", then there is a webpage called "Report7.aspx" that has this code in the Page_Load()

--------------------------
Dim rptFile as New clsRpt("<fileLocationPath>")
rptFile.setReportDBLogon("<servername>","<database>","<userid>","<password>")
Session("oRpt") = rptFile.Report
Response.Redirect("viewRpt.aspx")
--------------------------

Hope this helps,
Bryan Gordon,
Crystal Tactics
bgordon@crystaltactics.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top