Solved

How do I add a dynamic parameter to my crystal report?

Posted on 2013-05-23
10
300 Views
Last Modified: 2013-08-21
I have an ASP .NET 3.5 [C#] application that is using crystal reports. I want to, if possible, design a report (which i've already done), and in the designer add a dynamic parameter field that prompts the user for a value (preferably from a drop down list of valid values) and have it actually work. Currently when I add the parameter field in the designer, save it and then go out to the web page a couple things are happening. 1st, my list (data set) isn't filtered to only the values that meet / match the parameter. 2nd, when i attempt to click into or change the parameter value off to the left upper corner I get an error messag similar to: "Object not set to a value". How do I get this to work as I need it to?
0
Comment
Question by:mikesExpertExchange
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 39191859
How did you create the parameter?

What do you mean it isn't filtered?
It will show all values for the field

mlmcc
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 39191946
parameter creation
param creation
when i say it isn't filtered, i mean that based on the value i pass to the parameter field it appears that i still get all the data and not just the data that matches the parameter. also, when i initially started trying this out today, i would get a: " (?) " symbol in the upper left corner that when i clicked it, it would partially open a drop down that held a list of values for my parameter. it didn't matter though because when i would click in the drop down box to attempt to select a value, I would get the error telling me: "Object not set to an instance" (or some variation of that). but never the less that icon no longer shows up. just some information i thought might be helpful to pass along.
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 39192039
i finally was able to get the parameter icon / symbol to show  up again. in the included picture. if you look just below the printer icon, (upper left corner of the image) you'll see this: (?). when i click on it, to the right of it a box/rectangle appears that is partially cut off near the bottom. within that box/rectangle is a drop down that contains all of the valid possible values for my parameter. how ever, as soon as I try to choose one or edit the value i get the error shown in the image.

parameter error
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 100

Expert Comment

by:mlmcc
ID: 39192077
For filtering, what is your selection formula?

Is the Object not set to an instance from Crystal or the code running the report?

mlmcc
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 39192093
i'm not sure what object the error is referring to. I don't have a formula for the filter. just the parameter that i created. do i need to create a formula, setting a value in the report to the value of the parameter? this is what my Page_Load event looks like, if it helps (see code snippet).

protected void Page_Load(object sender, EventArgs e)
    {
        //SET NO TIME TABLE FOR WEEKLY LOG REPORT
        Utility.PrepNoTimeTable();<wbr ></wbr>

        ReportDocument report;

        if (Session["REP"] == null)
        {

            ReportDocument rpt = new ReportDocument();
            rpt.Load(Server.MapPath("~<wbr ></wbr>/WeeklyLog<wbr ></wbr>RptII.rpt"<wbr ></wbr>).ToString<wbr ></wbr>());

            SqlConnectionStringBuilder<wbr ></wbr> Conn = new SqlConnectionStringBuilder<wbr ></wbr>(Configura<wbr ></wbr>tionManage<wbr ></wbr>r.Connecti<wbr ></wbr>onStrings[<wbr ></wbr>"SQLExpres<wbr ></wbr>s"].Connec<wbr ></wbr>tionString<wbr ></wbr>);
            ConnectionInfo myConnectionInfo = new ConnectionInfo();


            ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
            ParameterRangeValue rangeVal = new ParameterRangeValue();
            ParameterValues curvalues = new ParameterValues();

            foreach (ParameterFieldDefinition parafld in rpt.DataDefinition.Paramet<wbr ></wbr>erFields)
            {
                if (parafld.DiscreteOrRangeKi<wbr ></wbr>nd.ToStrin<wbr ></wbr>g() == "test")
                {
                    discreteVal.Value = Request.QueryString[parafl<wbr ></wbr>d.Paramete<wbr ></wbr>rFieldName<wbr ></wbr>];
                    if (discreteVal.Value != null)
                    {
                        curvalues.Add(discreteVal)<wbr ></wbr>; parafld.ApplyCurrentValues<wbr ></wbr>(curvalues<wbr ></wbr>);
                    }
                }
            }

            myConnectionInfo.ServerNam<wbr ></wbr>e = ".\\sqlexpress";
            myConnectionInfo.DatabaseN<wbr ></wbr>ame = "studytimetrackerprime";
            myConnectionInfo.UserID = "mydbUserID";
            myConnectionInfo.Password = "********";
            setDBLOGONforREPORT(myConn<wbr ></wbr>ectionInfo<wbr ></wbr>); 

            //FillWeeklyLogRpt(rpt);

            RepointReport(rpt, Conn);
            Session["REP"] = rpt;
            report = rpt;
        }
        else
        {
            report = (ReportDocument)Session["R<wbr ></wbr>EP"];
        }

        CrystalReportViewer1.Repor<wbr ></wbr>tSource = report;
    }

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39192329
Yes you need to use the parameter in the record selection
Probably something like

{YourField} = {?Parameter}


When you click OK on the error what happens?
Do you get placed in the code or does a formula in the report open?

mlmcc
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 39192372
with the debugger on it does put me in the code, but it doesn't error out anywhere in the code. with it off, nothing opens. i have set that formula up. i placed it in the report header (in the designer). still nothing has changed. is there another place i should've put it?

crystal formula
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 39192400
In the report
Click REPORT --> SELECTION FORMULA --> RECORD

Add the formula there

mlmcc
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 39192518
i think what its come down to is that there is a lot of inconsistent behavior. sometimes it won't prompt for anything after an initial rendering (and prompting of the database credentials) of the page. it often prompts for the database log on which i've set to disabled in the html, so i don't quite understand that. the parameter pane, when its available doesn't allow for me to change the parameter. i think i'm gonna have to create custom pages for each variation of the report unfortunately. i just can't seem to get this thing to give me any stable results or behavior. i must be missing something major about how i have my report written or the viewer set up / configured.
0
 
LVL 1

Author Closing Comment

by:mikesExpertExchange
ID: 39428220
thank you. also i am still getting help from you with this topic in another question
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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