2008-12-15 122 views
14

我正在寻找一些帮助,以通过VB.NET和ASP.NET以编程方式将参数传递给SSRS报告。这似乎应该是一个相对简单的事情,但我没有多少运气找到这方面的帮助。如何以编程方式将参数传递给SSRS报告

有没有人有什么建议去哪里得到这个帮助,或者甚至一些示例代码?

谢谢。

回答

15

您可以执行以下操作::(它可以在本地报告中使用,例如在Full Blown SSRS报告中。但在全模式下,使用适当的类,参数部分保持不变)

LocalReport myReport = new LocalReport(); 
myReport.ReportPath = Server.MapPath("~/Path/To/Report.rdlc"); 

ReportParameter myParam = new ReportParameter("ParamName", "ParamValue"); 
myReport.SetParameters(new ReportParameter[] { myParam }); 

// more code here to render report 
+1

如果我不使用本地报告但不希望在url上留下显式值,该怎么办? – Leonardo 2015-02-24 14:20:46

11

如果报表服务器直接访问,则可以在查询字符串传递参数,如果你是一个URL访问repoort:

http://MyServer/ReportServer/?MyReport&rs:Command=Render&Param1=54321&Param2=product

您可以通过添加在年底下面添加输出格式

& RS:URL的格式= Excel中

& rs:格式= PDF

+1

将这些参数作为URL传递似乎是为别人破解报告打开大门。对于一个内部网站来说这可能没问题,但可能不适合面向公众的网站。 – LunaCrescens 2009-07-06 20:59:12

1

这已经有一段时间,因为我没有这个代码,但它可以帮助: 您的Web项目必须有一个网站,而不是“ASP.Net Web Application”类型的项目,否则您将无法添加下面提到的参考。 右键单击项目并添加一个ASP.Net文件夹--App_WebReferences。您必须指定SRS所在的服务器;选择.asmx。 添加后,该级别下的文件夹被称为RSService,在该文件夹下有两件事:reportservice.discomap & .wsdl。 在我的VB,我做进口RSService和进口System.Web.Services.Protocols,然后...

Dim MyRS As New ReportingService 

报告服务是一个不同的服务器的网络服务器应用程序是对的,所以我”做T如下:MyRS.Credentials = System.Net.CredentialCache.DefaultCredentials

相反:MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3), 其中RS1/2/3是登录SRS箱,密码箱SRS,&域名”(这些被加密在我的web.config)

然后,批量粘贴:

MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3) 

Dim ReportByteArray As Byte() = Nothing 
Dim ReportPath As String = "/SRSSiteSubFolder/ReportNameWithoutRDLExtension" 
Dim ReportFormat As String = "PDF" 
Dim HistoryID As String = Nothing 
Dim DevInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>" 
'Dim x As ReportParameter - not necessary 
Dim ReportParams(0) As ParameterValue 
ReportParams(0) = New ParameterValue() 
ReportParams(0).Name = "TheParamName" 
ReportParams(0).Value = WhateverValue 

Dim Credentials As DataSourceCredentials() = Nothing 
Dim ShowHideToggle As String = Nothing 
Dim Encoding As String 
Dim MimeType As String 
Dim ReportHistoryParameters As ParameterValue() = Nothing 
Dim Warnings As Warning() = Nothing 
Dim StreamIDs As String() = Nothing 
'Dim sh As New SessionHeader() - not necessary 
''MyRS.SessionHeaderValue = sh - not necessary 

ReportByteArray = MyRS.Render(ReportPath, ReportFormat, HistoryID, DevInfo, ReportParams, Credentials, _ 
    ShowHideToggle, Encoding, MimeType, ReportHistoryParameters, Warnings, StreamIDs) 
'(Yay! That line was giving "HTTP error 401 - Unauthorized", until I set the credentials 
' as above, as explained by http://www.odetocode.com/Articles/216.aspx.) 

'Write the contents of the report to a PDF file: 
Dim fs As FileStream = File.Create(FullReportPath, ReportByteArray.Length) 
fs.Write(ReportByteArray, 0, ReportByteArray.Length) 
fs.Close() 

Call EmailTheReport(FullReportPath) 

If IO.File.Exists(FullReportPath) Then 
    IO.File.Delete(FullReportPath) 
End If 
2
ReportViewer1.LocalReport.DataSources.Clear(); 
ReportViewer1.Reset(); 
Label1.Visible = false; 
ReportViewer1.Visible = true; 
DataSet dataSet = new DataSet(); 
dataSet = new ClassBLL().Load_Report_Detail(TextBox1.Text, 
ddlType.SelectedValue, levelcode, fields); 
ReportDataSource datasource = new ReportDataSource("DataSet_StoreprocedureName", 
dataSet.Tables[0]); 

if (dataSet.Tables[0].Rows.Count == 0) 
{ 
    ReportViewer1.Visible = false; 
} 

ReportViewer1.LocalReport.ReportPath = Server.MapPath("") + @"\Report.rdlc"; 
ReportViewer1.LocalReport.DataSources.Clear(); 
ReportViewer1.LocalReport.DataSources.Add(datasource); 
string fields="name,girish,Z0117"; 
string[] filedName = fields.Split(','); 
ReportParameter[] param = new ReportParameter[2]; 

//for (int i = 0; i < filedName.Length; i++) 
//{ 

param[0] = new ReportParameter(filedName[0], filedName[0], true); 
param[1] = new ReportParameter(filedName[3], filedName[3], true); 

// } 


ReportViewer1.LocalReport.SetParameters(param); 

ReportViewer1.ServerReport.Refresh(); 
+1

请在您的代码中添加一些注释。 – 2012-11-18 10:57:45

相关问题