Solved

Passing parameter to Crystal Reports

Posted on 2013-06-15
13
403 Views
Last Modified: 2013-06-22
I gave up on using the built in report designer with VS 2010 and switched to Crystal Reports, it seems like are alot more posts and examples for CR.

I am passing a parameter that is an integer to my crystal report, I am using this parameter to filter my report. In my report i created a parameter as a number type, I have added the parameter value to the heading in my report just to see what the value is and to make sure its at least making it to the report.
My value being past from my form is 1240 for instance, however the value in my heading is 1240.00 which causes the filter to not match so no records are displayed.
I don't see anywhere in crystal reports to change the type of the parameter to integer, I see you can change the number type of a field on the report, but not in the parameter.

I also have this formula I dropped onto the details section of my report.
{Issues.IssueID} = {?IssueID1}

I have another report that I am passing a string parameter which is working fine, its just when I try to pass an int that I am having a problem.

Hopefully that made sense.

MW
0
Comment
Question by:WINN2012
  • 6
  • 5
  • 2
13 Comments
 
LVL 10

Expert Comment

by:adriankohws
ID: 39250031
The easiest way is to treat it as a string and pass over, then you won't have problem.
And I am also curious, if you indeed pass an integer, how it became a decimal?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39250117
WHen you create the parameter you should be able to set the type as a number.

Crystal only has a number type and the display is controlled by the formatting.

mlmcc
0
 

Author Comment

by:WINN2012
ID: 39250500
I tried changing the field to string in CR, that didn't work, it really has to do with the value when it gets into CR has a decimal, therefor when it does its search it cant find the record. Again, when passing strings its working fine, just with an int its not finding the record i want to print.
I am using the below code in my form.

Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Utility\Reports\IssueTrackerDetailReport.rpt")
 
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue
 
        Dim user As String = ""
        Dim pwd As String = ""
        cryRpt.SetDatabaseLogon(user, pwd)
 
        crParameterDiscreteValue.Value = idToOpen1
        crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("IssueID1")
        crParameterValues = crParameterFieldDefinition.CurrentValues
 
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
 
        CrystalReportViewer1.ReportSource = cryRpt
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39250517
As I stated, in Crystal there are only numbers 1234 is the same as 1234.0 when using a numeric comparison.

Can you uplod your rpt file?

mlmcc
0
 

Author Comment

by:WINN2012
ID: 39250561
Unfortunately I cannot access expert exchange on my work pc, so I have to tinker on it, then jump on my home pc.
 I did take a couple screen shots, that hopefully will help identify the problem, they are attached.
image001.png
image002.png
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39250686
What type is Issues.ID?

mlmcc
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:WINN2012
ID: 39250692
It is an integer.
Sure wish reports were as easy as msaccess reports.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39250709
Generally they are.

Try a VERIFY DATABASE.  

Are you getting any errors?
If so when?

mlmcc
0
 
LVL 10

Expert Comment

by:adriankohws
ID: 39251330
In your VB Code, you declare IssueID1 as integer?
0
 

Author Comment

by:WINN2012
ID: 39251712
Hi,
I've started over, just had to made to many changes, so..
I created a new report, for the datasource I selected a dataset from the "Project Data" list.
I just went through all the steps to create the report, adding the Issues table, then selecting ALL the field, which includes IssueID which is an integer.
I created a new form, added a Crystal Report Viewer, choose my report from the list.
Even with no parameters or formulas I dont get any data. If I refresh my report, it asks for my username and password. Strange thing is, The Server Name is IssueTrackerReportDetailsDataSet and the Database field is blank (grayed out). No matter what username and pw i use it dont work.
Now if i start over again but instead of choosing a dataset from "Project Data" and scroll down to "Create New Connection", then Microsoft OLE DB Provider for SQL Server, then Pick my Server, UserID, PW, and database and finally the table(s) I need, then drop them on the report. I can at least preview my data.

So I guess my question is, why can't I select my project datasources?

Please forgive me if I am being a knucklehead here, but I have just been beating myself up trying to understand how either the built in reports or crystal reports work.

I'm sure its something simple I am doing.

MW
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39251824
Did you follow the instructions in the referenced article?

mlmcc
0
 

Accepted Solution

by:
WINN2012 earned 0 total points
ID: 39251864
This works, maybe I was over complicating it?

Dim cryRpt As New ReportDocument cryRpt.Load("C:\Utility\Reports\IssueTrackerDetailReport.rpt")
       
Dim user As String = ""
Dim pwd As String = ""
cryRpt.SetDatabaseLogon(user, pwd)

cryRpt.RecordSelectionFormula = "{Issues.ID} = " & idToOpen1
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh
0
 

Author Closing Comment

by:WINN2012
ID: 39267779
Code found in the internet seems to work for what I need.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now