Solved

Passing parameter to Crystal Reports

Posted on 2013-06-15
13
404 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

21 Experts available now in Live!

Get 1:1 Help Now