2008-12-15 5 views
14

पर पैरामीटर कैसे पास करें I VB.NET और ASP.NET के माध्यम से एक एसएसआरएस रिपोर्ट में प्रोग्रामेटिक रूप से गुजरने वाले पैरामीटर पर थोड़ी मदद की तलाश में हूं। ऐसा लगता है कि यह करने के लिए अपेक्षाकृत सरल बात होनी चाहिए, लेकिन मुझे इस पर मदद करने में बहुत भाग्य नहीं मिला है।एसएसआरएस रिपोर्ट प्रोग्रामेटिक रूप से

क्या किसी के पास इस बारे में कोई सुझाव है कि इसके साथ सहायता पाने के लिए कहां जाना है, या शायद कुछ नमूना कोड भी?

धन्यवाद।

उत्तर

15

आप निम्न कार्य कर सकते हैं: (यह स्थानीय उभरती हुई एसएसआरएस रिपोर्टों में स्थानीय रिपोर्टों पर काम करता है। लेकिन पूर्ण मोड में, का उपयोग उचित वर्ग, पैरामीटर हिस्सा ही)

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

क्या होगा अगर मैं स्थानीय रिपोर्ट का उपयोग नहीं कर रहा हूं लेकिन यूआरएल पर स्पष्ट मूल्य नहीं छोड़ना चाहता हूं? – Leonardo

11

तो रिपोर्ट सर्वर सीधे पहुँचा जा सकता है, तो आप क्वेरी स्ट्रिंग में पैरामीटर पारित कर सकते हैं अगर आप एक यूआरएल के साथ repoort तक पहुँच रहे हैं:

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

आप अंत पर निम्न को जोड़कर उत्पादन स्वरूपण जोड़ सकते हैं

& रु:: यूआरएल का प्रारूप = एक्सेल

या

& आरएस: प्रारूप = पीडीएफ

+1

पैरामीटर पासिंग के रूप में एक यूआरएल लगता है जैसे कि यह किसी को अपनी रिपोर्ट को हैक करने के लिए दरवाजे खोलता है। यह एक आंतरिक साइट के लिए ठीक हो सकता है, लेकिन शायद सार्वजनिक सामना करने वाली साइट के लिए नहीं। – LunaCrescens

1

इसके बाद से मैं इस कोड किया समय हो गया है बनी हुई है, लेकिन यह मदद मिल सकती है: आपका वेब परियोजना एक वेब साइट हो गया है, और "एएसपी.Net वेब एप्लिकेशन" प्रकार की प्रोजेक्ट नहीं है, या आप नीचे उल्लिखित संदर्भ जोड़ने में सक्षम नहीं होंगे। प्रोजेक्ट पर राइट क्लिक करें और एएसपी.Net फ़ोल्डर जोड़ें - App_WebReferences। आपको उस सर्वर को निर्दिष्ट करना होगा जहां आपका एसआरएस है; .asmx का चयन करें। एक बार यह जोड़ा जाने के बाद, उस स्तर के नीचे वाले फ़ोल्डर को आरएसएस सेवा कहा जाता है, और उसके तहत 2 चीजें हैं: reportservice.discomap & .wsdl। मेरी वीबी में, मैं आयात RSService और आयात System.Web.Services.Protocols करते हैं, तो ...

Dim MyRS As New ReportingService 

रिपोर्टिंग सेवा वेब सर्वर अनुप्रयोग पर है तुलना में एक अलग सर्वर पर है, इसलिए मैं कर सकते हैं ' MyRS.Credentials = System.Net.CredentialCache.DefaultCredentials

बजाय: टी निम्न कार्य करें। MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3), जहां RS1/2/3 एसआरएस बॉक्स, एसआरएस बॉक्स करने के लिए पासवर्ड, & डोमेन नाम "करने के लिए प्रवेश कर रहे हैं (। ये मेरी 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

कृपया अपने कोड में कुछ टिप्पणी जोड़ें। –