Crystal Reports help

Solarion

Honorary Master
Joined
Nov 14, 2012
Messages
28,049
Reaction score
17,803
Hey guys, I'm very new to crystal reports and requesting help pls. I've been googling this problem to death so time to make a post. I'm trying to add a date range for a report, so basically to return all records between x & y date, but nothing I've tried has made a difference. This is my code:

Code:
Dim filename As String = "C:\temp\AgentUpdateReport.pdf"
Dim report = New ReportDocument

report.Load(Server.MapPath("Reports/AgentUpdateReport.rpt"))

report.SetParameterValue("datefrom", "2013-05-20")
report.SetParameterValue("dateto", "2013-05-25")

report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, filename)
report.Close()
report.Dispose()

and this is my selection formula (Which I'm not sure if I even need?)

http://s22.postimg.org/k6260t1dd/crystalreportings.jpg

That's what I have so far, and it's not working, the report itself still pulls records from months ago. Any suggestions?
 
I compared your code to similar code I am using, and it seems ok. The only real difference is that I set login details to the database at runtime.

my sequence:

Load
SetParams
ApplyLogin
Export
Dispose

Have you tried saving your .rpt without data? maybe it's a simple caching issue.
 
I compared your code to similar code I am using, and it seems ok. The only real difference is that I set login details to the database at runtime.

my sequence:

Load
SetParams
ApplyLogin
Export
Dispose

Have you tried saving your .rpt without data? maybe it's a simple caching issue.

Thanks a ton Bravo it's now working, it was a caching issue. Much appreciated! :D
 
Great!

I know how frustrating Crystal can be and help on the internet are useless most of the time.
 
Great!

I know how frustrating Crystal can be and help on the internet are useless most of the time.

Yup, Crystal is proving a real challenge. One more question; do I even need that Selection Formula at all? It seems to work fine without it.
 
Last edited:
Well I think it depends on you data source. If your query or stored procedure already caters for the parameters then no, but your data source contains all the data in you want to filter inside Crystal then yes.

I prefer the former. Crystal passes the parameters to the stored procedure and my stored procedure does the filter from the db.
 
just to add. my approach to crystal is to do as little as possible in crystal, I prepare my data in the underlying queries and procedures. Filters/Sorting/Grouping whatever, just to keep the report as simple as possible.
 
Great tips to think about thanks, still scratching the surface.

This is final code which works well.

Code:
Dim filename As String = "C:\temp\AgentUpdateReport.pdf"
Dim report = New ReportDocument

report.Load(Server.MapPath("Reports/AgentUpdateReport.rpt"))

'Subtract 5 days from today's date, reporting 5 days in arrears.
report.SetParameterValue("datefrom", DateTime.Today.AddDays(-5))
report.SetParameterValue("dateto", DateTime.Today.Date)

report.SetDatabaseLogon("xxxxxxx", "xxxxxxx")
report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, filename)

report.Close()
report.Dispose()
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X