When calling reportViewer.ServerReport.Render("name", "deviceInfo");
I get the following exception
ReportServerException occurred
Additional information: This report
requires a default or user-defined value for the report parameter
'MyParam'. To run or subscribe to this report, you must provide a
parameter value. (rsReportParameterValueNotSet)
But the report parameters I'm settting clearly contain 'MyParam';
reportViewer.ServerReport.SetParameters(reportParams);
If step through the code with the debugger reportParams is an IEnumerable of ReportParameter and one of the parameters has the name 'MyParam' with a string collection of (count 1) with a string value inside.
Any ideas?
You need to make sure the value for the "MyParam" is a single value, also check and make sure the "MyParam" parameter is defined from your report template and take string value, you could also add a default value from the report template itself.
var reportParams = new List<ReportParameter>();
// make sure access the first item from the string collection
var myParam = new ReportParameter("MyParam", stringCollection[0]);
reportParams.Add(myParam );
reportViewer.ServerReport.SetParameters(reportParams);
Related
I have a dynamic array contains JSON response and i'm trying to alter or add new child but it keeps giving me this error:
Additional information: 'System.Dynamic.DynamicObject' does not contain a definition for 'vault_data'
This is my code:
dynamic user = getData(apiKey); //return a dynamic JSON array .. vault_data contains a string
user.vault_data = "Trying to alter this child"; // here occur the error when I try to alter the child
user.data = "Trying to add new child"; // this will through the same error
Image:
Merry Christmas!
I think the best way to solve this is if you can debug on run-time just before the error happened to see what is the type assigned to the dynamic user. This info will be very useful for you to determine how to extract the data you want.
But since, at least from the image, we can see the user is an array, you should access it by first using the number index user[46] before you can access its members (which contains vault_data).
After that
If the member is actually a KeyValuePair (KVP) with "vault_data" being the key, you should try to give second index in key form user[46]["vault_data"] to access the value.
If it is not KVP, but a variable member, you can try to access it directly user[46].vault_data.
If it is, in fact, another array, then you may need to access the access it by second index in number form user[46][1] (user[46][0] being the vault_data and thus user[46][1] is the value you want to change).
And if it is a string, then you need to further parse user[46]
In all possibilities, the key is to access the member first by indexing the user array.
I'm trying to get the parameter of user name and replace its value with the session's username so I can pass to a Stored procedure inside the DRL to generate a table timestamp with this user name.
The parameter "username" is one of the parameters of the RDL which comes with default value and I'm trying to change it with the following code.
Replacing one of the ReportParameters:
var userParameter = GetUserParameter();
if (userParameter != null)
{
newParameters.Remove(newParameters.FirstOrDefault(param => param.Name.Contains(CurrentUserParameterName)));
newParameters.Add(userParameter);
}
Finding username ReportParameters:
var paremeters = ReportViewer.ServerReport.GetEditableHiddenParameters();
//finds parameter by its name, pelase view const value in CurrentUserParameterName
var userParameter = paremeters.FirstOrDefault(param => param.Name.Contains(CurrentUserParameterName));
if (userParameter != null)
{
userParameter.Values.Clear();
userParameter.Values.Add(Utils.GetUserName());
}
return userParameter;
Set Parameters to ServerReport:
ReportViewer.ServerReport.SetParameters(parameters);
After running the report, I get the message "The 'username' parameter is missing a value"
When I debug and look in the ServerReport.GetParameters() I can see that I do have the ReportParameter "username", I do have values (the new values), but its State is "MissingValidValue".
What am I doing wrong?
Thanks in advance,
Eddie
I've finally managed to fix this issue thanks to this article: http://technet.microsoft.com/en-us/library/dd220464.aspx
If you have specified available values for a parameter, the valid
values always appear as a drop-down list. For example, if you provide
available values for a DateTime parameter, a drop-down list for dates
appears in the parameter pane instead of a calendar control. To ensure
that a list of values is consistent among a report and subreports, you
can set an option on the data source to use a single transaction for
all queries in the datasets that are associated with a data source.
Since I entered a default value in the "available values" option in addition to putting it in the "default values", the report tried to validate the new session username, which wasn't listed as an "available value". Once I removed the values in "available values", the new ReportParameter that I supply in code-behind didn't have to be validated, and the report rendered successfully.
HY! I have a form application in visual studio 2010 and I want to create a report with report viewer and to add some parameters. I tried to add parameters from code but it didn`t work. I have this error:
FilterExpression expression for the tablix ‘Tablix1’ refers to the field ‘datastart’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope.
Report2.rdlc : error rsParameterReference: The FilterValue expression for the tablix ‘Tablix1’ refers to a non-existing report parameter ‘datastart’.
In my code a do this:
private void SetReportParameters()
{
ReportParameter[] parameters = new ReportParameter[2];
parameters[0] = new ReportParameter("datastart", dateTimePickerStartRaport.Text);
parameters[1] = new ReportParameter("dataStop", dateTimePickerStopRaport.Text);
this.reportViewer1.LocalReport.SetParameters(parameters);
}
and after calling this method a make a refresh on the report viewer
reportViewer1.RefreshReport();
I also look at other forums and I saw that I have to add the parameters to the report, but I didn`t manage out how must I do this. I also tried to add, in the properties windows of the report, some filters with value
=Parameters!datastart.Value
but this also didn`t work.
The error you get is because you try to specify your parameter like a field. In the expression-designer you have a special category called "Parameters". From there you can access your parameters.
The syntax is =Parameters![FieldName].Value. In your case for example =Parameters!datastart.Value.
Additionaly, note that the parameters must be declared in the "Report Data"-window under "Parameters". Its the same window as you use to declare your recordsets, however there is also a special category for parameters. There are also some options for the datatype and if specification of the parameter is mandatory.
So when you create report definition (rdl or rdlc file) you have to add parameters with exactly the same names. So for your case you have to add datastart and dataStop parameters. To do it just click Parameters in Report Data Window and click add new.
Try this:
ReportParameter PrmInvoiceNo = new ReportParameter("PrmInvoiceNo");
PrmInvoiceNo.Values.Add(this.InvNo.ToString());
this.reportViewer1.LocalReport.SetParameters(PrmInvoiceNo);
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.
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);
}