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!

How do I use a crystalreportviewer? 1

Status
Not open for further replies.

OhioSteve

MIS
Mar 12, 2002
1,352
0
0
US
Here is the situation:
1) I have all of the visual studio software.
2) I have an asp.net project.
3) I want to add a Crystal Report.
4) I have managed to create a report in the project.
5) I have used the toolbox to put a crystalreportviewer onto the web page.

6) I need to somehow tell this viewer to display the crystal report from my project. I suspect that I need to do something in the viewer's properties or maybe write something in page load property.

Please advise.
 
Hi,
In the code behind file of your web page, put the following code in the page load event:

dim rpt as yourreport
rpt = new yourreport

crystalreportviewer1.reportsource = rpt
'if you have database login then put this line
rpt.setdatabaselogon("user", "password")
crystalreportviewer1.databind()

That is all. good Luck
 
I tried:

Dim rpt As CrystalReport4
rpt = New CrystalReport4
CrystalReportViewer1.ReportSource = rpt
rpt.SetDatabaseLogon("userID", "password")
CrystalReportViewer1.DataBind()

I got:

"Logon Failed..."


Its a little confusing because my crystal report's data source is a dataset. I'm not using the DB table directly. So why do I need to .SetDatabaseLogon?


 
I myself am getting that error now, I think I will have to get help from crystal report support.

Thanks
 
I am reading a book on the subject. I will let you know if I make any progress.
 
This is what the book tells me to put into the CrystalReportViewer's onload event. In this example, you are making an independent connection to the db (so no dataset). Also, this is in a Windows forms environment rather than asp.net.

1 Me.Cursor = Cursors.WaitCursor
2 Try
3 Dim oRpt As New ReportDocument
4 oRpt.Load("..\Reports\" & strReportName)
5
6 Dim tbCurrent As 7CrystalDecisions.CrystalReports.Engine.Table
8 Dim tliCurrent As 9CrystalDecisions.Shared.TableLogOnInfo
10
11 For Each tbCurrent In oRpt.Database.Tables
12 tliCurrent = tbCurrent.LogOnInfo
13 With tliCurrent.ConnectionInfo
14 .ServerName = "jb1gs"
15 .UserID = "sa"
16 .Password = ""
17 .DatabaseName = Northwind
18 End With
19 tbCurrent.ApplyLogOnInfoInfo(tliCurrent)
20 Next tbCurrent
21 Viewer.reportsource = oRpt
22
23 Catch ex As Exception
24 MsgBox(ex.Message)
25 Finally
Me.Cursor = Cursors.Default
End Try

I get the blue line of doom on lines 3,4, and 21. Line 3 is understandable because strReportname is not defined. I don't understand the other two errors.
 
have you referenced the crystal reports object model for the code to be aware of the reportDocument class?

i have written a faq somewhere on CR, might help

faq766-5214

and most books ive found are hopeless, half the examples are missing things...
*
check this site out it really is very good!


Aftertaf

"Resolve is never stronger than the night before it was never weaker
 
Actually, after my last post I was able to fix the problems. This is working for me:

Me.Cursor = Cursors.WaitCursor
Try
Dim oRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
oRpt.Load("C:\directory\directory\Report1.rpt")
Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
For Each tbCurrent In oRpt.Database.Tables
tliCurrent = tbCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
.ServerName = "servername"
.UserID = "userid"
.Password = "password"
.DatabaseName = "sql server db name"
End With
tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent
CrystalReportViewer1.ReportSource = oRpt
Catch ex As Exception
MsgBox(ex.Message)
Finally
Me.Cursor = Cursors.Default
End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top