Solved

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

Posted on 2013-05-23
10
284 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
  • 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
 
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
Free Trending Threat Insights Every Day

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.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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