如何在SSRS中传递参数
本文关键字:参数 SSRS | 更新日期: 2023-09-27 18:09:09
我对SSRS很陌生,并且在传递参数方面遇到了困难。目前我正在做以下操作:
ReportViewer1.ServerReport.ReportPath = ConfigurationManager.AppSettings["serverPath"] + "MyReport";
List<ReportParameter> paralist = new List<ReportParameter>();
ReportParameter reportParam1 = new ReportParameter("LocationId", txtLocationId.Text);
ReportParameter reportParam2 = new ReportParameter("PrdAcctId", txtProductAccountId.Text);
ReportParameter reportParam3 = new ReportParameter("FromDate", frmdt);
ReportParameter reportParam4 = new ReportParameter("ToDate", todt);
ReportParameter reportParam5 = new ReportParameter("IntAmt", todt);
paralist.Add(reportParam1);
paralist.Add(reportParam2);
paralist.Add(reportParam3);
paralist.Add(reportParam4);
paralist.Add(reportParam5);
ReportViewer1.ServerReport.SetParameters(paralist);
当no。的参数设置。但在某些情况下,答案是否定的。的参数将在运行时根据用户输入决定。
现在我不知道怎么说no。.rdl文件中灵活的参数。例如,每个用户输入可以有n个FromDate和ToDate以及相应的IntAmt。
您可以调用GetParameters方法来获取所有当前报表参数,并遍历它们以查看每个参数是什么以及每个参数的各种属性:
开始:
ReportParameterInfoCollection param = ReportViewer1.ServerReport.GetParameters();
您可以尝试以下操作,它可以工作-将索引0替换为参数的序数值:
if (this.rptView.ServerReport.GetParameters()[0].Values.Count > 0)
{
string parvalue = this.rptView.ServerReport.GetParameters()[0].Values.ToString();
paramList.Add(new ReportParameter("ReportName", parvalue));
}
这不是对你问题的直接回答。我们的主页使用window.href
重定向到报表呈现页面,并将参数作为查询字符串传递。
注意:这是VB。Net代码,可以转换为等效的c#代码
代码后面
Public Function GetParametersList(ByVal reportRDLName As String) As List(Of String)
'Get these values from database. Following is a sample
Dim parametersList As New List(Of String)()
parametersList.Add("plantcd")
parametersList.Add("CountID")
Return parametersList
End Function
Public Function GetReportPath(ByVal reportRDLName As String) As String
'Get these values from database. Following is a sample
Dim reportPath As String = "/MyFolder/MyModule/"
Return reportPath
End Function
Protected Overrides Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
'--------------------------------------------------------
Me.EnableViewState = True
If Not Page.IsPostBack Then
vwreports.ServerReport.ReportServerCredentials = New MyCustomReportServerCredentials
vwreports.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
vwreports.ServerReport.ReportServerUrl = New Uri(ConfigurationManager.AppSettings("MyReportServer"))
Dim reportRDLName As String = Request.QueryString("rname").ToString()
Dim parametersList As List(Of String) = GetParametersList(reportRDLName)
Dim reportPath As String = GetReportPath(reportRDLName)
Dim countOfParameters As Integer = parametersList.Count
Dim parms As ReportParameter() = New ReportParameter(countOfParameters - 1) {}
Dim iterationCount As Integer = 0
For Each parameterName As String In parametersList
Dim parameterValue As String = Convert.ToString(Request.QueryString(parameterName))
If Not [String].IsNullOrEmpty(parameterValue) Then
parms(iterationCount) = New ReportParameter(parameterName, parameterValue)
iterationCount += 1
End If
Next
vwreports.ServerReport.ReportPath = reportPath + reportRDLName
vwreports.ServerReport.SetParameters(parms)
vwreports.ShowParameterPrompts = False
vwreports.ServerReport.Refresh()
End If
End Sub