Solved

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

Posted on 2013-05-23
10
291 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
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.

 
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

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

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

22 Experts available now in Live!

Get 1:1 Help Now