views:

133

answers:

3

I am using Visual Studie 2005 and SQL Server 2005. I trying to run some ssrs reports that I created on the server. Can I create paramters at run-time in my code even though I did not create the parameters in the report. Here is my sample code:

        ReportNum = Test.Left(cboReportList.Text, 9);
        reportViewer1.ServerReport.ReportServerUrl = new Uri  ("http://simsamwqs04.rsc.humad.com/reportserver");
        reportViewer1.ServerReport.ReportPath = "/Claims/Report Project1/" + ReportNum;

        //ReportViewer1.ServerReport.ReportPath = "/Report Project State/Report1";
        ReportParameter[] Params = new ReportParameter[1];
        Params[0] = new ReportParameter("fundctr", txtCenter.Text);
        reportViewer1.ServerReport.SetParameters(Params);
        reportViewer1.ServerReport.Refresh();
A: 

I'm not sure I understand your question, but if I do, it appears that you're asking if you can add parameters to a report in which they didn't previously exist.

If you didn't already create the parameters in the report, then what do you expect you could do with the parameters if you were to be able to create them at runtime? You would have nothing depending on them. You would have nothing in the report that would look for them.

Gabriel McAdams
A: 

I am new to sssrs so maybe I did not ask the question correctly. I am trying to filter the data based on any field in my dataset. How do add code in c sharp to filter the data at runtime?

Raja
A: 

You could possibly try creating all of the parameters that are necessary and deciding to use them in the SQL with the coalesce operator. Like so:

select field1,field2
from table_a
where /*sneaky part below*/
field1 = Coalesce(@ParamForField1, field1)
AND
field2 = Coalesce(@ParamForField2, field2)

This will effectively ignore the parameters if their value is null. It does not work in every situation though. It is a bit of a long loop around your problem, but may work for you.

doug_w