Creating an optional Parameter in ReportViewer - c#

How can I make a parameter in reportviewer as optional, so that if the parameter is empty or null then it is ignored and the report should not apply filter on it?

First you need to ensure that the parameter is nullable within SQL Server Report Builder. Double click on the parameter in question and select the Allow null value.
I would post an image but I do not have enough blah...
The final thing to make it work is to pass a null value to your report... This can be done in different ways, but this is how I was using it...
ReportViewer1.ServerReport.SetParameters(new ReportParameter(tb.ID, new string[] { null }));
Hopefully this helps.

Related

SSRS passing hidden parameter from web.config

I have a report that deals with presenting a table with data, I use the MvcReportViewerFluent to view the report on the page.
#(Html.MvcReportViewerFluent(Model.ReportPath)
.ReportParameters(Model.ReportParameter)
.Attributes(new { Height = 900, Width = "100%", style = "border: none" })
.ControlSettings(new ControlSettings() {ShowExportControls=true, AsyncRendering=true, ShowReportBody=true })
)
In the report there is a link that is built with the concatenation of various parameters including the baseUrl parameter of the hidden type, for a couple of days this parameter seems as if it were not populated but took its default value.
To populate this parameter I use the ReportParameters property to which I pass a dictionary with the parameter.
model.ReportParameter = new Dictionary<string, object>();
model.ReportParameter.Add("BaseUrl", ConfigurationManager.AppSettings["UrlBase"].ToString());
Note that in addition to this parameter, other parameters that work perfectly are presented on the screen.
I also tried to make this parameter visible and I saw that it is not even populated, the strange fact is that in the test environment it gave the same problem which then solved itself without making any changes.
Not sure exactly what you meant by "the baseUrl parameter of the hidden type". In order to pass hidden parameters to ssrs you just append it to a query string like so:
[BaseurlofSSRS]?[myhiddenparamname]=[value]
This should work.
This was due to a cache problem that remained hanging on the server after some changes were made to the report itself, for some reason the parameters were not updated, the solution was to delete the report and reload it on the server.

Pass a null date to a crystal report parameter using SetParameterValue

I have a situation where I have a crystal report where I pass in a start and end date via rdoc.SetParameterValue this works fine, except that, I do not want it to show a date if I pass nothing for the date variable, I just want it to be blank
To an attempt to do so i have written
if (DateStart != defaultDate)
{
rdoc.SetParameterValue("DStart", DateStart);
}else
{
rdoc.SetParameterValue("DStart", "");
}
Which gives me the error The types of the parameter field and parameter field current values are not compatible of course, this makes sense because I am trying to set a date to a string variable.
However, I am unable to think of a solution, nor do I see any solution in the Parameter's menu.
Appreciate it if I be given some assistance to solve this.
Regards
You may change the parameter type to string and pass the date as string:
DateStart.ToString()
I don't like this solution, but it works. Usually i just require the date.

How to "force" an Crystal Reports optional parameter to not need a value

I have a crystal report that has an optional parameter called Supplier Name.
My Selection Expert logic is set up like this:
**if hasvalue({?Supplier Name}) then
{q_InStockItems_ByUnitSize_vw.primary_supplier_id} = {?Supplier Name}
else
true
So if no value is entered in the optional parameter, all the records are returned.
I am populating the parameter via C# using the following line of code:
InventoryReport.SetParameterValue("Supplier Name", SupplierID);
The problem I am experiencing is that I want to have the ability to not programmatically pass a value to the optional parameter, so all the records are returned.
If I don't specifically provide a value to the optional parameter, Crystal Reports opens the report, and displays the parameter entry window.
I can hit ok and all the records get displayed, but I'm hoping there is some way to skip over the above step.
Try this
if IsNull({?Supplier Name}) then true;
else {q_InStockItems_ByUnitSize_vw.primary_supplier_id} = {?Supplier Name};

SSRS report parameter

I have a problem with rendering report with correct parameter.
We have RDL report that has date parameter with default value which is an expression "=today()".
In project i have the following code in c#
for(int i = 0; i < 15; i++)
{
serverReport.SetParameters(new ReportParameter("dt1",date.ToString()));
File.WriteAllBytes(path, serverReport.Render("PDF"));
}
For first iteration sql stored procedure is called with the default parameter and following iterations are called with passed date(i checked it with sql profiler).
I want to mension that in loop i have many other reports with exact same default date parameter but the problem is with this one. I have compared all parameter properties in 2 repors(one that works and the other that is not working properly), but they are identical. I cant find any difference.
If i delete default value "=today()" then report is working fine.
Maybe sameone had similar problem and recommend me something about this. Thanks in advance.
A few things to check:
SetParameters takes IEnumerable<ReportParameter> not a single ReportParameter object. Call it like this instead:
serverReport.SetParameters(new ReportParameter[] { ReportParameter("dt1", date.ToString()) } );
Make sure that the parameter does not have the available values filled in as well as the default value. If the date passed is not one of the valid values (if applied) it won't work. For example, if the available values are set to =Today then the only report that will run properly is the first one that coincidentally uses that value.
Are you sure that date.ToString() is passing an appropriate and valid date?
Does the server's report parameter match the development environment? Parameter settings aren't automatically updated so that any modifications made on the server aren't overwritten by deploying the report again. Check the server's report parameters and update if necessary, or simply delete and redeploy the report.
Try to completely remove the not working report within the server (and to test,also one of the working) and re-deploy both to the server. you could also check in reporting manager for the parameter settings, because there the difference might be visible.
I had that kind of issues before with report parameters and know that the parameter settings are not overwritten correctly all the time you deploy the report.

SSRS with 'Available Values By Query' does not return ValidValues property

I have a web application using a SSRS 2010 service, and I'm having an issue getting back the valid values for a parameter. The parameter allows multiple values and is of type Text. In the report I create, I am getting available values by query, as opposed to 'specify values'. When I call GetItemParameters the ValidValues property is empty.
If my Report specifies values instead of getting values from query, then the ValidValues property is filled in completely.
I'm hoping someone knows a way to get that property filled out when getting from query, because I'd hate to have my report writers specifying hundreds of (often changing) values individually.
Thanks!
Your link ReportingService2010.GetItemParameters gives following information
If any parameters values are based on a query and you are interested
in returning the query-based parameters' valid values list, set
ForRendering to true. In addition, for query-based parameters, you
must pass in all of the credential information required to return the
query parameters.
Did you set ForRendering to true value as it is said in this link?

Categories

Resources