Assign multiple values to a parameter in Crystal Reports - c#

I have added a parameter to my report with the option "Allow Multiple Values" checked.
This is a status column (IE, Proposed, In Progress, Completed, Canceled), and I want the user to be able to select which (and how many) different OrderStatus to report on.
How I normally set parameters is:
report.SetParameterValue("#dtBegin", dtBegin.DateTime);
What I tried to do for the multiple values was something like this:
//pseudo loop
foreach(int intOrderStatus in intSelectedOrderStatuses)
{
report.Parameter_OrderStatus.CurrentValues.AddValue(intOrderStatus);
}
I have checked it does add the values to the OrderStatus parameter, but when the report runs, the CrystalReports dialog pops up and asks me to enter values for the OrderStatus parameter. So it seems as though the values aren't "commited" to the parameter. I have done a number of searches and can't figure out why it's not working.
Thanks,

Just set the parameter value with an array of ints.
report.SetParameterValue("#OrderStatus", new int[]{1,2,3});
in the select expert you would use the in operator.
{table.order_status_id} in {?#OrderStatus}

What you can do is, make a normal parameter field,i.e without multiple values, only discreet values true, all you need to pass is 1,2,3,4. "," is the delimiter for separation use what ever you think works for you, then in record selection formula simply put
{table.order_status_id} in split({#OrderStatus}, ",")
all you need to pass from you page is the string 1,2,3,4 and it should work

Have you set the parameter to Hidden in the Crystal Reports parameter options?

I haven't tried this, but I think that you should be able to add intOrderStatus to either a ParameterDiscreteValue or ParameterRangeValue and pass that into Parameter_OrderStatus.CurrentValues instead of intOrderStatus.

Well i have same issue. The work around is very simple. Don't add data source after parameters. e.g
report.SetParameterValue("#dtBegin", dtBegin.DateTime);
report.SetParameterValue("#dtBegin2", dtBegin.DateTime1);
//Note datasource is assigned after parameters
report.SetDatasource(dataset);
The crystal report will refresh parameters before applying data source to report.
The below is the not popup discrete dialog box
//Note Datasource is applied before parameters
report.SetDatasource(dataset);
report.SetParameterValue("#dtBegin", dtBegin.DateTime);
report.SetParameterValue("#dtBegin2", dtBegin.DateTime1);

Following is tested in Crystal Reports version 13.0.20:
1) In Parameter Fields section add new parameter as follow:
Name: ParamMultipleOrderStatus
Type: Number
Value Options:
Allow multiple values: true
2) Choose the Select Expert Record ... in Crystal Reports and code may like this (use = operator):
{Orders.OrderStatus} = {?ParamMultipleOrderStatus}
3) Use following code:
foreach (int intOrderStatus in intSelectedOrderStatuses)
{
report.ParameterFields["ParamMultipleOrderStatus"].CurrentValues.AddValue(intOrderStatus);
}

Related

C# rdlc for a single object, no table

I'm trying to make an rdlc report in Visual Studio 2015 for a single instance of an object. It seems as though I always have to pass in an enumerable list as the datasource, and it always has a table.
Is it possible to just pass in a single object and not have a table? I want to have a background image and use text boxes to display the data that I want to display.
Thank you for any responses!
There are a couple of ways to accomplish this.
If it's just a single item, why not just use a parameter? Just pass your single value via a parameter.
If you want to go the data source route, yes, you have pass in an enumerable, but that is as easy as this:
var data = new string[] { "my value"}
and using the First function:
=First(Fields!ProductNumber.Value, "Category")
Either way, you can still use textboxes.

How to remove Database fields from Crystal report programmatically [duplicate]

I have a section in a Crystal Report that I want to suppress. I need to suppress it if there are 0 rows in a particular table in the dataset I am using. How would I do this? The Record Number special field provided appears to be an internal count of records in the report, and does not relate to the rows in the underlying data table.
I am creating the report from C#, but I cannot suppress the section from the code (it doesn't fit the project structure) - I must be able to do it from the report itself. The table concerned is definitely being passed to the report in the dataset, but it contains 0 rows. There must be a way to establish this inside the report itself.....
Can anyone please point me in the right direction?
In the Crystal Reports designer, view the properties of your section and there should be an option to Suppress, which you can give it a formula to return the appropriate boolean value.
You could then use the Count() function within that formula and (I believe) you can pass the name of your dataset to the Count() function to get the number of rows in that dataset.
I did the same thing on a complex report about 3 months ago but I don't have access to the report any more having changed jobs so I'm sorry I cannot be more specific, but hoepfully this gives you a starting point.
Just had a quick Google - try this.
If the section does only contain database fields and f.e. no text fields, then you could use the setting "Suppress Blank Section" in the "Section Export" (rightclick section) for that section.
As an alternative you could use the following formula in the "Suppress" in the "Section Export" for that section:
IsNull({table.field})
"{table.field}" is one of the fields in the dataset.
Hope this helps.
Go to "Section Expert" and click "Supress (No Drill-Down)" and try adding this:
IF {"DragYourFieldHere"} = "" then true else false
Create one dummy group,check on its header for each page,add the header in the group header of the dummy group.

Can we equate 2 parameters in crystal reports c# (oracle db)?

I have a simple search box in my web app and i want to provide options of searching the employee table for either name, employee id or position etc. Ie, basically a drop down and then a text box to enter the value. The columns currently being chosen are from the same table.
I have assumed i need 2 parameters equating both such that one refers to the column name and the other to its value. Is it right? And if so, how do we pass the sql query on formula editor?
Check the below code:
if ({?cat}="NAME")
then
{FATHIMA.NAME}={?val}
else
if({?cat}="POSITION")
then
{FATHIMA.POSITION}={?val}
Provided there should be value in {?val} and that value should match with the value in database.
Yes i have used Record Selection Formula. The code I've written there is:
if ({?cat}="NAME")
then
{?val}={FATHIMA.NAME}
else
if({?cat}="POSITION")
then
{?val}={FATHIMA.POSITION}
---where "NAME" and "POSITION" are column names. I have passed them manually as items in a drop down list. But the report gives an empty result. 'cat' is the parameter holding the selected value from the drop down.

Winform to Crystal Report value changes

Why does a value from a certain Winform change when passing to a report?
for example from a form I have a string 1311-0015 but when I pass it to a Formula Field it becomes 1,296.00
http://i.imgur.com/oeIwrAU.jpg
Passing it to a TextObject doesn't change the value it's still 1311-0015 but I can't use TextObjects in formulas in Crystal Report.
Would like to know why this is happening and how to remedy the problem.
this is the code from the winForm:
report.DataDefinition.FormulaFields["SOS"].Text = transactionId; ((TextObject)report.Section2.ReportObjects["Text3"]).Text = transactionId;
the value I was passing to the crystal report:
public string transactionId = "1311-0015";
You said you are passing the value to a formula field. If there is nothing in the formula, and you pass 1311 - 15 to the formula, it will evaluate it. Instead of a formula field, use a text box or modify the string so it doesn't come out like an equation. For your transactionID value try something like:
""1311" & "-" & "0015""
You may need to have two separate public string transactionId variables.
You can pass this string as parameter.
First, create a parameter field in you Crystal Reports editor. (Right button, New...)
Code something like this:
string transactionID = "1311-0015";
yourRpt.SetDatasource(youDataSource);
yourRpt.Parameters.SetParameterValue("transactionID", transactionID);
Now, you just need to drag and drop the parameter field into the report.
You should create a parameter and use its value inside the formula.
In order to avoid showing parameters dialog box make sure that the parameter value is set (you should do this in your code) and set:
yourReport.EnableParameterPrompting = false;

SSRS URL Parameter won't set

I have the following c# code in a web form:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string url;
string startdate;
string enddate;
string costcenter;
string account;
//url = "http://server/reportserver?/Finance/Cost Spending/Cost Center Details&rs:Command=Render&rc:Parameters=false";
url = "http://server/reportserver?/Finance/Cost Spending/Cost Center Totals&rs:Command=Render&rc:Parameters=false";
costcenter = "&costcenter=990";
startdate="&startdate=" + Convert.ToString(txtStartDate.Text);
enddate = "&enddate=" + Convert.ToString(txtEndDate.Text);
account="&account=" + Convert.ToString(GridView1.SelectedRow.Cells[1].Text);
url =url + startdate + enddate + costcenter + account;
//TextBox1.Text = Convert.ToString(GridView1.SelectedRow.Cells[1].Text);
Response.Redirect(url, false);
}
I've tested a very similer version of this code against another report, the only different being the costcenter parameter. The other report worked fine, but every time i run this code i get the error: "the 'costcenter' parameter is missing a value". The only thing i can think of that's significantly different between the two reports is that in the Cost Center Totals report the costcenter parameter is used to populate the accounts parameter (both are multi-select).
Here's what the parameters page looks like:
Are you using multiple datasets in your report? If so, try setting the datasets to execute serially:
Open the data source dialog in report designer
Select the "Use Single Transaction" checkbox
Some other troubleshooting steps you can try:
Try removing the Report Server Command "&rs:Command=Render" from the query string and see what happens.
Also, if you change the Viewer Command to true, are you able to at least see that the parameters are populated properly (ie: "&rc:Parameters=true"?
I've been under the impression that one difference between running a report on the web server and running it in code is that in code it does not bother with the "Available Values" queries for parameters. In code, you aren't selecting a human-readable label from a drop-down which then passes in the corresponding value. Instead, you just provide the value to the parameter.
So, have you tried not specifying the cost center parameter at all? If the account parameter is all the report's recordsets really are based on, then it may be superfluous to set it.
Update:
Since the time I wrote this answer originally I've learned that dependent parameters (at least in SSRS 2008) must be after the parameter(s) they're dependent on. Make sure your parameters are ordered in a sensible way.
It looks like that's what you've done, I just wanted to mention the possibility.
Check that the Costcenter 990 is in your database!
I did some testing. I have a table "Person" with 4 rows and a PersonID 1 to 4. If set &PersonID=5 for a required single value parameter with "&rc:Parameters=true" then I get a drop-down box so I can choose one of the 4 valid persons.
If I set &PersonID=5 with "&rc:Parameters=false" then I get the message "the PersonID parameter is missing a value".
I faced similar kind of issue. Removing the parameter dependency made it work. I had parameter B depending on parameter A. It worked perfectly when you access the report server directly. But when I tried to bind it programmatically to the report viewer control, even after supplying the parameter using ReportParameter and adding to Parameters list, it was merely saying that "The 'Parameter B' is missing".
So, I went back to the report server. Redeployed the report by removing parameter dependency. It worked. :-)
Ok, I figured out the issue thanks to Alison's poke at the parameters/data sets. What was happening was I had 4 parameters, start date, end date, cost center, and accounts. In the report the account data set relies on the cost center parameters to populate the drop down list. I created a copy of the report, removed the cost center parameter, and removed the data set from the account parameter. I updated the code and ran it and BAM! It worked.

Categories