简体   繁体   English

在运行时为ssrs动态创建参数

[英]dynamically create parameter at runtime for ssrs

I am using Visual Studie 2005 and SQL Server 2005. I trying to run some ssrs reports that I created on the server. 我正在使用Visual Studie 2005和SQL Server2005。我试图运行在服务器上创建的一些ssrs报告。 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();

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. 您将在报告中找不到任何可以找到它们的东西。

You could possibly try creating all of the parameters that are necessary and deciding to use them in the SQL with the coalesce operator. 您可以尝试创建所有必需的参数,然后决定通过合并运算符在SQL中使用它们。 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. 解决您的问题可能需要很长时间,但可能对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM