zoukankan      html  css  js  c++  java
  • 用C#访问SSRS自动导出SSRS报表

    一、              新建一个winform应用程序WindowsFormsApplication1

    二、              添加web引用 。

    报表服务:http://dbpdhkcax05:80/webservice/ReportService2005.asmx

    报表执行服务:http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx

    右击“引用”-> 添加服务引用->输入URL地址点“前往”载入服务后点“高级”-服务引用设置->点“添加web引用”->在此画面将2个服务都加入项目。

    三、              web服务引用如图示。(web服务引用的节点一开始没有,在添加web服务引用后自动产生).

    四、              建一form用于输入参数。

    五、              点OK产生报表(VS2008)

    1.插入命名空间引用

    1 using WindowsFormsApplication1.dbpdhkcax05_rs;
    2 using WindowsFormsApplication1.dbpdhkcax05_rsexec;
    View Code

    2.Click OK 代码

     1             dbpdhkcax05_rs.ReportingService2005 rs2005 = new ReportingService2005();
     2             dbpdhkcax05_rsexec.ReportExecutionService rsExec = new ReportExecutionService();
     3 
     4             rs2005.Credentials = System.Net.CredentialCache.DefaultCredentials;
     5             rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
     6             rsExec.Timeout = -1;
     7 
     8             rs2005.Url = "http://dbpdhkcax05:80/webservice/ReportService2005.asmx?WSDL";
     9             rsExec.Url = "http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx?WSDL";
    10 
    11 
    12             string reportPath = "/Operation/PortalReports/Reliability Details";
    13             string fileName = @"C:\testRel.xls";
    14 
    15             string format = "EXCEL";
    16             string historyID = null;
    17             string devInfo = null;
    18             bool _forRendering = false;
    19 
    20             dbpdhkcax05_rs.ParameterValue[] _values = null;
    21             dbpdhkcax05_rs.ReportParameter[] _parm = null;
    22             dbpdhkcax05_rs.DataSourceCredentials[] _cred = null;
    23 
    24             _parm = rs2005.GetReportParameters(reportPath, historyID,_forRendering, _values, _cred);
    25 
    26             dbpdhkcax05_rsexec.ExecutionInfo execinfo = rsExec.LoadReport(reportPath, historyID);
    27 
    28             dbpdhkcax05_rsexec.ParameterValue[] parameters = new WindowsFormsApplication1.dbpdhkcax05_rsexec.ParameterValue[3];
    29             // Prepare report parameter.
    30             //ParameterValue[] parameters = new ParameterValue[3];
    31             parameters[0] = new dbpdhkcax05_rsexec.ParameterValue();
    32             parameters[0].Name = "StartDate";
    33             parameters[0].Value = txtFromDate.Text;
    34             parameters[1] = new dbpdhkcax05_rsexec.ParameterValue();
    35             parameters[1].Name = "EndDate";
    36             parameters[1].Value = txtToDate.Text; 
    37             parameters[2] = new dbpdhkcax05_rsexec.ParameterValue();
    38             parameters[2].Name = "Company";
    39             parameters[2].Value = txtCompanyId.Text;
    40 
    41             rsExec.SetExecutionParameters(parameters, "en-us");
    42             Byte[] results;
    43             string encoding = String.Empty;
    44             string mimeType = String.Empty;
    45             string extension = String.Empty;
    46             string[] streamIDs = null;
    47             dbpdhkcax05_rsexec.Warning[] warning = null;
    48             results = rsExec.Render(format, devInfo, out extension, out mimeType, out encoding, out warning, out streamIDs);
    49             using (FileStream stream = File.OpenWrite(fileName))
    50             {
    51                 stream.Write(results, 0, results.Length);
    52 
    53             }
    View Code
  • 相关阅读:
    Uva673 Parentheses Balance
    cordforce Educational Codeforces Round 47 补题笔记 <未完>
    cordforce 495 补题 <未完>
    linux 基本命令笔记
    app审核相关
    CATransform3D
    UITableView点击切换状态分析
    iOS大转盘抽奖
    被忽视的控件UIToolbar
    AVPlayerViewController视频播放器
  • 原文地址:https://www.cnblogs.com/sxypeace/p/5182182.html
Copyright © 2011-2022 走看看